19 using System.Collections.Generic;
21 namespace Lucene.Net.Util.Cache
28 public class SimpleMapCache<TKey, TValue> : Cache<TKey, TValue>
30 internal System.Collections.Generic.Dictionary<TKey, TValue> map;
32 public SimpleMapCache()
33 : this(new System.Collections.Generic.Dictionary<TKey, TValue>())
37 public SimpleMapCache(System.Collections.Generic.Dictionary<TKey, TValue> map)
42 public override TValue Get(System.Object key)
44 return map[(TKey)key];
47 public override void Put(TKey key, TValue value_Renamed)
49 map[key] = value_Renamed;
52 public override bool ContainsKey(System.Object key)
54 return map.ContainsKey((TKey)key);
57 protected override void Dispose(
bool disposing)
63 public virtual System.Collections.Generic.HashSet<TKey> KeySet()
65 return new HashSet<TKey>(map.Keys);
70 return new SynchronizedSimpleMapCache(
this);
74 private class SynchronizedSimpleMapCache : SimpleMapCache<TKey, TValue>
76 private System.Object mutex;
77 private SimpleMapCache<TKey, TValue> cache;
79 private bool isDisposed;
81 internal SynchronizedSimpleMapCache(SimpleMapCache<TKey, TValue> cache)
87 public override void Put(TKey key, TValue value_Renamed)
91 cache.Put(key, value_Renamed);
95 public override TValue Get(System.Object key)
99 return cache.Get(key);
103 public override bool ContainsKey(System.Object key)
107 return cache.ContainsKey(key);
111 protected override void Dispose(
bool disposing)
115 if (isDisposed)
return;
119 cache.Dispose(disposing);
123 base.Dispose(disposing);
127 public override HashSet<TKey> KeySet()
131 return cache.KeySet();
135 internal override Cache<TKey, TValue> GetSynchronizedCache()