Exemple #1
0
 public void Put(Key key, Value value)
 {
     try
     {
         _storage.Add(key, value);
         _evictionPolicy.KeyAccessed(key);
     }
     catch (Exception)
     {
         Console.WriteLine("Got storage full. Will try to evict");
         Key keyToEvict = _evictionPolicy.EvictKey();
         if (keyToEvict == null)
         {
             throw new Exception("Unexpected state. Storage full and no key to evict");
         }
         _storage.Remove(keyToEvict);
         Console.WriteLine($"Evicting item {keyToEvict}");
         Put(key, value);
     }
 }