public void Add(string key, object value, TimeSpan timeout) { CacheItemRemovedCallback callback = null; // only need call back if item is in the locking states if (CacheEntries.ContainsKey(key)) { callback = ItemRemovedCallback; } Insert(key, value, null, timeout, CacheItemPriority.Normal, callback); }
/* * private void Insert(string key, object obj, CacheDependency dep, DateTimeOffset timeframeOffset, CacheItemPriority priority, CacheItemRemovedCallback callback) * { * if (obj != null) * { * var cache = GetCache(); * cache.Insert(key, obj, dep, timeframeOffset.UtcDateTime, Cache.NoSlidingExpiration, priority, callback); * } * } */ /// <summary> /// Items the removed callback. /// </summary> /// <param name="key">The key.</param> /// <param name="value">The value.</param> /// <param name="reason">The reason.</param> internal static void ItemRemovedCallback(string key, object value, CacheItemRemovedReason reason) { if (reason == CacheItemRemovedReason.Expired) { var cacheEntry = CacheEntries.Get(key); if (cacheEntry != null) { lock (cacheEntry.Lock) { CacheEntries.Remove(key); } } } }
public object GetAndLock(string key, TimeSpan timespan, out object lockHandle) { lockHandle = CacheEntries.GetLock(key); return(Get(key)); }