public void AddOrLockKey(TKey key, TValue value, out TValue valueAddedOrLocked) { CacheEntry <TValue> cacheEntry = null; valueAddedOrLocked = value; CacheEntry <TValue> cacheEntry1 = new CacheEntry <TValue>(value); using (WriterLock writerLock = new WriterLock(this.readerWriterLock)) { if (!this.cache.TryGetValue(key, out cacheEntry)) { if (this.cache.Count < base.MaxCacheSize) { this.cache.Add(key, cacheEntry1); valueAddedOrLocked = value; } else { object[] maxCacheSize = new object[1]; maxCacheSize[0] = base.MaxCacheSize; throw new OverflowException(ExceptionHelpers.GetExceptionMessage(Resources.CannotAddMoreToCache, maxCacheSize)); } } else { cacheEntry.Lock(out valueAddedOrLocked); } } }
public bool TryRemove(TKey key) { bool flag; using (WriterLock writerLock = new WriterLock(this.readerWriterLock)) { if (this.cache.ContainsKey(key)) { this.cache.Remove(key); flag = true; } else { flag = false; } } return(flag); }
public override void DoCleanup(DateTime checkPoint) { using (WriterLock writerLock = new WriterLock(this.readerWriterLock)) { List <TKey> tKeys = new List <TKey>(); foreach (TKey key in this.cache.Keys) { CacheEntry <TValue> item = this.cache[key]; if (!this.CanItemBeRemoved(item, checkPoint)) { continue; } tKeys.Add(key); } foreach (TKey tKey in tKeys) { CacheEntry <TValue> cacheEntry = this.cache[tKey]; this.cache.Remove(tKey); cacheEntry.Dispose(); } } }