Example #1
0
 public Task EvictKeyAsync(TKey key)
 {
     return(_taskFactory.StartNew(() =>
     {
         lock (_cache)
         {
             if (_cache.ContainsKey(key))
             {
                 var value = _cache[key];
                 _cache.Remove(key);
                 KeyEvicted?.Invoke(this, new KeyEvictedEventArgs <TKey, TValue>(key, value));
             }
             else
             {
                 throw new KeyNotFoundException($"Missing Key:{key}");
             }
         }
     }));
 }
Example #2
0
 public Task RemoveKeyAsync(TKey key)
 {
     return(_taskFactory.StartNew(() =>
     {
         lock (_cache)
         {
             if (_cache.ContainsKey(key))
             {
                 var value = _cache[key];
                 _backingStore.RemoveKey(key);
                 _cache.Remove(key);
                 KeyEvicted?.Invoke(this, new KeyEvictedEventArgs <TKey, TValue>(key, value));
             }
             else
             {
                 _backingStore.RemoveKey(key);
             }
         }
     }));
 }