public TCacheItem GetOrCreate <TCacheItem>(string key, Func <string, CacheUpdateCancellationToken, TCacheItem> updateCache, CacheItemPolicy cachePolicy) where TCacheItem : class { key.Requires("key").IsNotNullOrWhiteSpace(); updateCache.Requires("updateCache").IsNotNull(); cachePolicy.Requires("cachePolicy").IsNotNull(); object item; bool stale; if (TryGet(key, out item, out stale)) { if (stale) { onAsyncUpdateCache.BeginInvoke(key, updateCache, cachePolicy, null, null); } return(item as TCacheItem); } var shadowKey = GetShadowKey(key); var shadowLock = GetLock(shadowKey); lock (shadowLock) { if (TryGet(key, out item)) { return(item as TCacheItem); } item = OnUpdateCache(key, updateCache, cachePolicy); return(item as TCacheItem); } }
public void SetOrUpdateWithoutCreate(string key, object value, CacheItemPolicy policy) { key.Requires("key").IsNotNullOrWhiteSpace(); policy.Requires("policy").IsNotNull(); SetOrUpdateWithoutCreate(new CacheItem(key, value), policy); }
public void SetOrUpdateWithoutCreate(CacheItem item, CacheItemPolicy policy) { item.Requires("item").IsNotNull(); policy.Requires("policy").IsNotNull(); var shadowKey = GetShadowKey(item.Key); lock (GetLock(item.Key)) { storeCache.Set(item.Key, item.Value, ObjectCache.InfiniteAbsoluteExpiration); shadowCache.Set(shadowKey, DummyShadowObject, policy); } }
internal CacheUpdateCancellationToken(CacheItemPolicy cacheItemPolicy) { cacheItemPolicy.Requires("cacheItemPolicy").IsNotNull(); this.CacheItemPolicy = cacheItemPolicy; }