/// <summary> /// Removes an item from the cache /// </summary> /// <param name="Key">Key associated with the item to remove</param> public virtual void Remove(KeyType Key) { if (Exists(Key)) { lock (InternalCache) { if (Exists(Key)) { InternalCache.Remove(Key); } } } }
/// <inheritdoc /> public void Remove(IEnumerable <FormKey> keys) => InternalCache.Remove(keys);
/// <inheritdoc /> public bool Remove(FormKey key) => InternalCache.Remove(key);
public virtual void HandleEvent(EntityChangedEventData <TEntity> eventData) { InternalCache.Remove(GetCacheKey(eventData.Entity)); }
public static void Remove(string key) { Check.Argument.IsNotNullOrEmpty(key, "key"); InternalCache.Remove(key); }
/// <summary> /// Compacts the specified percentage. /// </summary> /// <param name="percentage">The percentage.</param> public override void Compact(double percentage) { if (InternalCache is null) { return; } int CurrentCount = InternalCache.Count; int ItemsToRemove = (int)Math.Round(CurrentCount * percentage, MidpointRounding.AwayFromZero); int TargetCount = CurrentCount - ItemsToRemove; if (TargetCount == CurrentCount) { return; } var CurrentTime = DateTimeOffset.UtcNow; lock (LockObject) { var Items = InternalCache.Values.ToArray(); var EntriesToRemove = new List <CacheEntry>(); var LowPriorty = new List <CacheEntry>(); var NormalPriorty = new List <CacheEntry>(); var HighPriorty = new List <CacheEntry>(); for (int i = 0; i < Items.Length; i++) { var Item = Items[i]; if (!CheckValid(Item, CurrentTime)) { Item.Invalid = true; EntriesToRemove.Add(Item); --CurrentCount; } else { switch (Item.Priority) { case CachePriority.Low: { LowPriorty.Add(Item); break; } case CachePriority.Normal: { NormalPriorty.Add(Item); break; } case CachePriority.High: { HighPriorty.Add(Item); break; } } } } CurrentCount = ExpirePriorityBucket(CurrentCount, TargetCount, EntriesToRemove, LowPriorty); CurrentCount = ExpirePriorityBucket(CurrentCount, TargetCount, EntriesToRemove, NormalPriorty); CurrentCount = ExpirePriorityBucket(CurrentCount, TargetCount, EntriesToRemove, HighPriorty); foreach (var Item in EntriesToRemove) { CurrentSize -= (Item.Size ?? 0); InternalCache.Remove(Item.Key); EvictionCallback(Item.Key, Item.Value, EvictionReason.Expired, this); } } }