private void OnItemsRemoved(ItemsRemovedEventArgs <T> i) { if (this.ItemsRemoved != null) { this.ItemsRemoved(this, new ItemsRemovedEventArgs <T>(i.OldItems)); } }
/// <summary> /// Called when an entry is removed from <see cref="InnerCache"/>. /// </summary> /// <param name="sender"> /// The object that raised the message. /// </param> /// <param name="e"> /// Event-specific arguments. /// </param> private void InnerCache_ItemsRemoved(object sender, ItemsRemovedEventArgs <TKey> e) { Interlocked.Increment(ref MessagesSent); if (!RedisCacheMessageSuppressionContext.IsSet(Name)) { if (IsolateTenants) { var message = new RedisPubSubPerTenantCacheMessage <TKey>(new PerTenantCacheMessage <RedisPubSubCacheMessage <TKey> >(new RedisPubSubCacheMessage <TKey>(RedisPubSubCacheMessageAction.Remove, e.Items))); PerTenantChannel.Publish( message, PublishOptions.FireAndForget, true, RedisPubSubCacheHelpers.PerTenantMergeAction ); } else { Channel.Publish( new RedisPubSubCacheMessage <TKey>(RedisPubSubCacheMessageAction.Remove, e.Items), PublishOptions.FireAndForget, true, RedisPubSubCacheHelpers.MergeAction ); } } }
/// <summary> /// Clear the cache. /// </summary> public void Clear() { // Prevent multiple threads calling this code concurrently. // Threads will skip clearing the cache if it is being cleared by another thread. // If this code is called concurrently the OnItemsRemoved callback // maybe called multiple times when in reality the items were removed once. if (!Monitor.TryEnter(_syncRoot)) { return; } try { var itemsRemovedEventArgs = new ItemsRemovedEventArgs <TKey>(_cache.Keys.ToList()); _cache.Clear(); if (InnerCache != null) { InnerCache.Clear( ); } OnItemsRemoved(itemsRemovedEventArgs); } finally { Monitor.Exit(_syncRoot); } }
/// <summary> /// Raise the <see cref="ItemsRemoved"/> event. /// </summary> /// <param name="args"> /// Event-specific args. /// </param> protected void RaiseItemsRemoved(ItemsRemovedEventArgs <TKey> args) { if (ItemsRemoved != null) { ItemsRemoved(this, args); } }
/// <summary> /// Called when an item is removed from the inner cache. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void CacheOnItemsRemoved(object sender, ItemsRemovedEventArgs <TKey> args) { if (ItemsRemoved != null) { ItemsRemoved(this, args); } }
private void Libary_ItemsRemoved(object sender, ItemsRemovedEventArgs <CodeSnippet> e) { if (_Updating != 0) { return; } Changed = true; TreeNodes.RemoveRange(e.Removed.Select(p => p.Id)); }
/// <summary> /// Raised when items are removed from the cache. /// </summary> /// <param name="sender"> /// The object that raised the event. /// </param> /// <param name="itemsRemovedEventArgs"> /// Event-specific args. /// </param> private void CacheOnItemsRemoved(object sender, ItemsRemovedEventArgs <TKey> itemsRemovedEventArgs) { // Items are removed here to ensure the CacheInvalidator handles // cases where items are removed from the cache outside invalidation, e.g. // LRU cache or timeout cache. EntityToCacheKey.RemoveValues(itemsRemovedEventArgs.Items); FieldTypeToCacheKey.RemoveValues(itemsRemovedEventArgs.Items); RelationshipTypeToCacheKey.RemoveValues(itemsRemovedEventArgs.Items); EntityInvalidatingRelationshipTypesToCacheKey.RemoveValues(itemsRemovedEventArgs.Items); }
/// <summary> /// Raise the <see cref="ItemsRemoved"/> event. /// </summary> /// <param name="itemsRemovedEventArgs"> /// Event specific args. This cannot be null. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="itemsRemovedEventArgs"/> cannot be null. /// </exception> protected void OnItemsRemoved(ItemsRemovedEventArgs <TKey> itemsRemovedEventArgs) { if (itemsRemovedEventArgs == null) { throw new ArgumentNullException(nameof(itemsRemovedEventArgs)); } ItemsRemovedEventHandler <TKey> itemsRemovedEventHandler = ItemsRemoved; if (itemsRemovedEventHandler != null) { itemsRemovedEventHandler(this, itemsRemovedEventArgs); } }
/// <summary> /// Called when an item is removed from the cache. /// </summary> /// <param name="sender"> /// The object that raised the event. /// </param> /// <param name="args"> /// The event args. /// </param> private void OnItemsRemovedAction(object sender, ItemsRemovedEventArgs <TKey> args) { ItemsRemoved.AddRange(args.Items); }
/// <summary> /// Called when an item is removed from the inner cache. /// </summary> /// <param name="sender"></param> /// <param name="itemsRemovedEventArgs"></param> private void CacheOnItemsRemoved(object sender, ItemsRemovedEventArgs <Tuple <long, TKey> > itemsRemovedEventArgs) { RaiseItemsRemoved(new ItemsRemovedEventArgs <TKey>(itemsRemovedEventArgs.Items.Select(i => i.Item2))); }
/// <summary> /// Called when an item is removed from the inner cache. /// </summary> /// <param name="sender"></param> /// <param name="itemsRemovedEventArgs"></param> private void CacheOnItemsRemoved(object sender, ItemsRemovedEventArgs <TKey> itemsRemovedEventArgs) { RaiseItemsRemoved(new ItemsRemovedEventArgs <TKey>(itemsRemovedEventArgs.Items)); }
/// <summary> /// Raise the <see cref="ItemsRemoved"/> event. /// </summary> /// <param name="args"> /// Event-specific args. /// </param> protected void RaiseItemsRemoved(ItemsRemovedEventArgs <TKey> args) { var handler = ItemsRemoved; handler?.Invoke(this, args); }