public TValue this[TKey key] { get { TValue value; var cacheKey = new KeyIdentifier <TKey>(key); if (!_cache.TryGetValue(cacheKey, out value)) { throw new KeyNotFoundException("Key:" + key + " could not be found in the cache."); } return(value); } set { if (Contains(key)) { var cacheKey = new KeyIdentifier <TKey>(key); _cache[cacheKey] = value; } TryAdd(key, value); PerformEviction(); } }
public bool Contains(TKey key) { lock (this) { var cacheKey = new KeyIdentifier <TKey>(key); return(_cache.ContainsKey(cacheKey)); } }
public bool TryRemove(TKey key, out TValue value) { lock (this) { var cacheKey = new KeyIdentifier <TKey>(key); return(_cache.TryRemove(cacheKey, out value)); } }
public bool TryAdd(TKey key, TValue value) { lock (this) { var cacheKey = new KeyIdentifier <TKey>(key); if (!_cache.TryAdd(cacheKey, value)) { return(false); } PerformEviction(); return(true); } }
public int CompareTo(object obj) { int result = 0; if (obj is KeyIdentifier <TKey> ) { KeyIdentifier <TKey> other = (KeyIdentifier <TKey>)obj; if (other._refCount > _refCount) { result = -1; } else if (other._refCount < _refCount) { result = 1; } } return(result); }