public override TItem Get(string key) { if (!Store.ContainsKey(key)) { return(null); } Keys.Remove(key); Keys.AddLast(key); return(Store[key]); }
public override void Put(string key, TItem value) { if (!Store.ContainsKey(key)) { if (Store.Count == MaxSize) { // remove first key (the oldest) string keyToRemove = Keys.First(); Keys.RemoveFirst(); Store.Remove(keyToRemove); } Keys.AddLast(key); Store.Add(key, value); } else { Keys.Remove(key); Keys.AddLast(key); Store[key] = value; } }
public override void Put(string key, TItem value) { if (!Store.ContainsKey(key)) { if (Store.Count < MaxSize) { Store.Add(key, value); Keys.AddLast(key); } else { string firstKey = Keys.First(); Keys.RemoveFirst(); Store.Remove(firstKey); } } else { Keys.Remove(key); Keys.AddLast(key); Store[key] = value; } }