/// <summary> /// Adds the given key to the end of the LRU list. /// This key is the most recently used key. /// Note: Assumes that it is called in a thread-safe manner (i.e. <see cref="_lock"/> is held /// by the caller.) /// </summary> /// <param name="cacheKey">Key to add to the end of the LRU list.</param> private void AddToEndOfLRU(FunctionDataCacheKey cacheKey) { if (LRUList.Contains(cacheKey)) { RemoveFromLRU(cacheKey); } LRUList.AddLast(cacheKey); }
public void LRUList_Basic() { LRUList list; V v, v0, v1, v2, v3; list = new LRUList(); Assert.AreEqual(0, list.Count); list.Add(v0 = new V(0)); list.Add(v1 = new V(1)); list.Add(v2 = new V(2)); list.Add(v3 = new V(3)); Assert.AreEqual(0, ((V)list[0]).Value); Assert.AreEqual(1, ((V)list[1]).Value); Assert.AreEqual(2, ((V)list[2]).Value); Assert.AreEqual(3, ((V)list[3]).Value); list.Touch(v0); Assert.AreEqual(1, ((V)list[0]).Value); Assert.AreEqual(2, ((V)list[1]).Value); Assert.AreEqual(3, ((V)list[2]).Value); Assert.AreEqual(0, ((V)list[3]).Value); list.Remove(v2); v = (V)list.RemoveLRU(); Assert.AreEqual(1, v.Value); v = (V)list.RemoveLRU(); Assert.AreEqual(3, v.Value); v = (V)list.RemoveLRU(); Assert.AreEqual(0, v.Value); v = (V)list.RemoveLRU(); Assert.IsNull(v); }
/// <summary> /// Removes the given key from the LRU list, if it exists. /// Note: Assumes that it is called in a thread-safe manner (i.e. <see cref="_lock"/> is held /// by the caller.) /// </summary> /// <param name="cacheKey">Key to remove from the LRU list.</param> private void RemoveFromLRU(FunctionDataCacheKey cacheKey) { LRUList.Remove(cacheKey); }