Exemple #1
0
        /// <summary>
        /// Removes the specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="suppressFullInvalidation">if set to <c>true</c> [suppress full invalidation].</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">key</exception>
        public bool Remove(EntityRelationshipCacheTypeKey key, bool suppressFullInvalidation = false)
        {
            using (var entityTypeContext = new EntityTypeContext( ))
            {
                IEntity entity = EntityCache.Instance.Get(key.EntityId);

                if (entity != null)
                {
                    entityTypeContext.Merge(key.EntityId, entity.TypeIds);
                }

                bool result = ProviderRemove(key);

                HashSet <long> typeIds = entityTypeContext.Get(key.EntityId);

                if (!suppressFullInvalidation)
                {
                    var message = new EntityRelationshipCacheMessage( );
                    message.SuppressFullInvalidation = suppressFullInvalidation;
                    message.RemoveTypeKeys.Add(new SerializableEntityRelationshipCacheTypeKey(SerializableEntityId.Create(key.EntityId, typeIds), key.Direction, key.TypeId));

                    MessageChannel.Publish(message, PublishOptions.FireAndForget, false, MergeMessages);
                }

                return(result);
            }
        }
        /// <summary>
        ///     Tries the parse.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="cacheKey">The cache key.</param>
        /// <returns></returns>
        public static bool TryParse(string key, out EntityRelationshipCacheTypeKey cacheKey)
        {
            cacheKey = null;

            if (!string.IsNullOrEmpty(key))
            {
                string[] args = key.Split('_');

                if (args.Length == 3 && !string.IsNullOrEmpty(args[0]) && !string.IsNullOrEmpty(args[1]) && !string.IsNullOrEmpty(args[2]))
                {
                    long id;

                    if (long.TryParse(args[0], out id))
                    {
                        Direction direction;

                        if (Enum.TryParse(args[1], out direction))
                        {
                            long typeId;

                            if (long.TryParse(args[2], out typeId))
                            {
                                cacheKey = new EntityRelationshipCacheTypeKey(id, direction, typeId);
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
Exemple #3
0
        /// <summary>
        ///     Providers the remove.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <returns></returns>
        private bool ProviderRemove(EntityRelationshipCacheTypeKey key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            bool result;

            lock ( _syncRoot )
            {
                if (key.Direction == Direction.Forward)
                {
                    IDictionary <long, ISet <long> > typedCachedValues;

                    result = _forwardCache.Remove(key.EntityId, key.TypeId, out typedCachedValues);

                    _reverseCache.Remove(key.EntityId, key.TypeId, out typedCachedValues);
                }
                else
                {
                    IDictionary <long, ISet <long> > typedCachedValues;

                    result = _reverseCache.Remove(key.EntityId, key.TypeId, out typedCachedValues);

                    _forwardCache.Remove(key.EntityId, key.TypeId, out typedCachedValues);
                }
            }

            return(result);
        }
        /// <summary>
        ///     Determines whether the specified <see cref="System.Object" /> is equal to this instance.
        /// </summary>
        /// <param name="obj">
        ///     The <see cref="System.Object" /> to compare with this instance.
        /// </param>
        /// <returns>
        ///     <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public bool Equals(EntityRelationshipCacheTypeKey obj)
        {
            if (obj == null)
            {
                return(false);
            }

            return(base.Equals(obj) && TypeId == obj.TypeId);
        }