public static bool Update(string key) { object lck = CacheLockbox.GetInternalLock(key); if (lck == null) { return(false); } lock (lck) InternalCallback(key); return(true); }
internal static void ItemRemovedCallback(string key, object value, CacheItemRemovedReason reason) { if (reason == CacheItemRemovedReason.Expired) { CacheEntry cacheEntry = CacheLockbox.GetCacheEntry(key); // If the sliding expirarion was not reached... if (cacheEntry.LastUse.Add(cacheEntry.SlidingExpiration) > DateTime.Now) { //... the object will be temporary inserted in cache... cache_.Insert(key, value, null, DateTime.Now.Add(TimeSpan.FromSeconds(30.0)), TimeSpan.Zero, CacheItemPriority.Low, null); //...reload and reinsert the item into the cache again. ThreadPool.QueueUserWorkItem(delegate(object o) { string s = o.ToString(); lock (CacheLockbox.GetInternalLock(s)) { InternalCallback(s); } }, key); } } }
internal static object InternalCallback(string key) { CacheEntry cacheEntry = null; if (!CacheLockbox.TryGetCacheEntry(key, out cacheEntry)) { return(null); } CacheLoaderDelegate cacheLoader = cacheEntry.CacheLoader; if (cacheLoader == null) { return(null); } object obj2 = null; try { obj2 = cacheLoader(); } catch (Exception exception) { if (cache_loader_error_delegate_ != null) { try { cache_loader_error_delegate_(key, exception); } catch { } } } if (obj2 != null) { Insert(key, obj2, null, (int)cacheEntry.RefreshInterval.TotalSeconds, CacheItemPriority.Normal, new CacheItemRemovedCallback(NCache.ItemRemovedCallback)); CacheLockbox.UpdateCacheEntry(key, DateTime.Now); } return(obj2); }
public static object GetCacheEntryLock(string key, TimeSpan refreshInterval, TimeSpan slidingExpiration, CacheLoaderDelegate loaderDelegate) { return(CacheLockbox.GetLock(key, refreshInterval, slidingExpiration, loaderDelegate)); }
public static object GetCacheEntryLock(string key, int refreshIntervalSeconds, int slidingExpirationSeconds, CacheLoaderDelegate loaderDelegate) { return(CacheLockbox.GetLock(key, TimeSpan.FromSeconds((double)(refreshIntervalSeconds * Factor)), TimeSpan.FromSeconds((double)(slidingExpirationSeconds * Factor)), loaderDelegate)); }
public static object GetCacheEntryLock(string key) { return(CacheLockbox.GetLock(key)); }