protected object Get(ICacheKey key) { try { _lock.EnterUpgradeableReadLock(); object value; if(cache.TryGetValue(key.GetStringKey(), out value)) { return value; } OnMiss(key, out value); var cacheKey = BuildUniqueStringKey(key); var opts = new MemoryCacheEntryOptions(); if (_useAbsoluteExpiration) { opts.AbsoluteExpiration = AbsoluteExpiration; } else if (_useSlidingExpiration) { opts.SlidingExpiration = SlidingExpirationSpan; } cache.Set(key.GetStringKey(), value, opts); return value; } finally { if(_lock.IsUpgradeableReadLockHeld) { _lock.ExitUpgradeableReadLock(); } } }
private string BuildUniqueStringKey(ICacheKey key) { return String.Format("{0};{1};{2}", GetType().FullName, key.GetType().FullName, key.GetStringKey()); }