Example #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);
            }
        }
Example #2
0
 /// <summary>
 ///     Merges the messages.
 /// </summary>
 /// <param name="existingMessage">The existing message.</param>
 /// <param name="newMessage">The new message.</param>
 private void MergeMessages(EntityRelationshipCacheMessage existingMessage, EntityRelationshipCacheMessage newMessage)
 {
     existingMessage.ClearForward |= newMessage.ClearForward;
     existingMessage.ClearReverse |= newMessage.ClearReverse;
     existingMessage.RemoveKeys.UnionWith(newMessage.RemoveKeys);
     existingMessage.RemoveTypeKeys.UnionWith(newMessage.RemoveTypeKeys);
 }
Example #3
0
        /// <summary>
        ///     Clears this instance.
        /// </summary>
        public void Clear( )
        {
            ProviderClear( );

            var message = new EntityRelationshipCacheMessage
            {
                ClearForward = true,
                ClearReverse = true
            };

            MessageChannel.Publish(message, PublishOptions.FireAndForget, false, MergeMessages);
        }
Example #4
0
        /// <summary>
        ///     Clears the specified direction.
        /// </summary>
        /// <param name="direction">The direction.</param>
        public void Clear(Direction direction)
        {
            ProviderClear(direction);

            var message = new EntityRelationshipCacheMessage( );

            if (direction == Direction.Forward)
            {
                message.ClearForward = true;
            }
            else
            {
                message.ClearReverse = true;
            }

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