public void Put(object key, object value) { lock (_syncRoot) { cache.Add(key, value); } }
public void PutAndRemove() { int size = 10; IDictionary cache = new LRUMap(size); cache.Add("key:" + 1, "data:" + 1); cache.Remove("key:" + 1); Assert.IsNull(cache["key:" + 1]); }
public void AddDoesBoundsChecking() { var map = new LRUMap(128); for (int i = 0; i < 200; i++) map.Add("str" + i, i); Assert.That(map.Count, Is.EqualTo(128)); }
public object this[object key] { get { lock (_syncRoot) { object result = softReferenceCache[key]; if (result != null) { strongReferenceCache.Add(key, result); } return(result); } } }
public void PutWithNoSizeLimit() { int size = 10; IDictionary cache = new LRUMap(); for (int i = 0; i < size; i++) { cache.Add("key:" + i, "data:" + i); } for (int i = 0; i < size; i++) { string data = (string)cache["key:" + i]; Assert.AreEqual("data:" + i, data, "Data is wrong."); } }
public object this[object key] { [MethodImpl(MethodImplOptions.Synchronized)] get { lock (SyncRoot) { object result = softReferenceCache[key]; if (result != null) { strongReferenceCache.Add(key, result); } return(result); } } }
public void GetEntrySet() { int size = 10; IDictionary cache = new LRUMap(size); for (int i = 0; i < size; i++) { cache.Add("key:" + i, "data:" + i); } Assert.AreEqual(size, cache.Keys.Count, "Set contains the wrong number of items."); // check minimal correctness foreach (DictionaryEntry entry in cache) { Assert.AreNotEqual(-1, entry.Value.ToString().IndexOf("data:")); } }
public void PutWithSizeLimitOfZero() { IDictionary cache = new LRUMap(0); cache.Add("key", "data"); string data = (string)cache["key"]; Assert.IsNull(data, "Data is wrong."); }