public ICache GetOrCreateSubCache(string name) { this._syncObject.EnterUpgradeableReadLock(); try { MemCache result = null; if (!_subCaches.TryGetValue(name, out result)) { this._syncObject.EnterWriteLock(); try { if (!_subCaches.TryGetValue(name, out result)) { result = new MemCache(this); this._subCaches.Add(name,result); TryStartTask(); } } finally { this._syncObject.ExitWriteLock(); } } return result; } finally { this._syncObject.ExitUpgradeableReadLock(); } }
static void RemoveExpired(MemCache cache, DateTime now, DateTime expireTime, List<CacheItem> removed) { cache._items = RemoveExpiredItems(now, expireTime, cache._items, removed); var newSubs = new SortedDictionary<string, MemCache>(); foreach (var pair in cache._subCaches) { var sub = pair.Value; RemoveExpired(sub,now,expireTime,removed); if (sub._items.Count != 0 || sub._subCaches.Count != 0) { newSubs.Add(pair.Key,sub); } } cache._subCaches = newSubs; }
private MemCache(MemCache parent) { this.Parent = parent; this._syncObject = parent._syncObject; }