// remove key / value pair if the given key exists and has expired private void CheckExpiration(TKey key) { if (LastAccessed.ContainsKey(key) && DateTime.Now - LastAccessed[key] > Timeout) { Remove(key); } }
public new bool ContainsKey(TKey key) { CheckExpiration(key); if (LastAccessed.ContainsKey(key)) { LastAccessed[key] = DateTime.Now; } return(base.ContainsKey(key)); }
public virtual new bool TryGetValue(TKey key, out TValue value) { CheckExpiration(key); if (LastAccessed.ContainsKey(key)) { LastAccessed[key] = DateTime.Now; } return(base.TryGetValue(key, out value)); }
public virtual new TValue this[TKey key] { get { CheckExpiration(key); if (LastAccessed.ContainsKey(key)) { LastAccessed[key] = DateTime.Now; } return(base[key]); } set { LastAccessed[key] = DateTime.Now; base[key] = value; } }