public void Add(TKey key, TValue value) { bool flag = false; try { if (this.items.Count == this.highWatermark) { int num = this.highWatermark - this.lowWatermark; for (int i = 0; i < num; i++) { TKey tKey = this.mruList.Last.Value; this.mruList.RemoveLast(); TValue item = this.items[tKey].@value; this.items.Remove(tKey); this.OnSingleItemRemoved(item); this.OnItemAgedOutOfCache(item); } } MruCache <TKey, TValue> .CacheEntry cacheEntry; cacheEntry.node = this.mruList.AddFirst(key); cacheEntry.@value = value; this.items.Add(key, cacheEntry); this.mruEntry = cacheEntry; flag = true; } finally { if (!flag) { this.Clear(); } } }
public bool TryGetValue(TKey key, out TValue value) { MruCache <TKey, TValue> .CacheEntry cacheEntry; if (this.mruEntry.node == null || key == null || !key.Equals(this.mruEntry.node.Value)) { bool flag = this.items.TryGetValue(key, out cacheEntry); value = cacheEntry.@value; if (flag && this.mruList.Count > 1 && !object.ReferenceEquals(this.mruList.First, cacheEntry.node)) { this.mruList.Remove(cacheEntry.node); this.mruList.AddFirst(cacheEntry.node); this.mruEntry = cacheEntry; } return(flag); } else { value = this.mruEntry.@value; return(true); } }