public static bool RefreshByCacheKey(string key) { if (!CacheLockbox.ContainsCacheEntry(key)) { return(false); } ThreadPool.QueueUserWorkItem(delegate(object o) { Update(o.ToString()); }, key); return(true); }
public static bool Update(string key) { if (!CacheLockbox.ContainsCacheEntry(key)) { return(false); } lock (CacheLockbox.GetInternalLock(key)) { InternalCallback(key); } return(true); }
internal static void ItemRemovedCallback(string key, object value, CacheItemRemovedReason reason) { if (reason == CacheItemRemovedReason.Expired) { CacheEntry cacheEntry = CacheLockbox.GetCacheEntry(key); if (cacheEntry.LastUse.Add(cacheEntry.SlidingExpiration) > DateTime.Now) { _cache.Insert(key, value, null, DateTime.Now.Add(TimeSpan.FromSeconds(30.0)), TimeSpan.Zero, CacheItemPriority.Low, null); ThreadPool.QueueUserWorkItem(delegate(object o) { string _key = o.ToString(); lock (CacheLockbox.GetInternalLock(_key)) { InternalCallback(_key); } }, key); } } }
public static void RefreshByPattern(string pattern) { ThreadPool.QueueUserWorkItem(delegate(object _pattern) { IEnumerator <string> enumerator = CacheLockbox.Keys.GetEnumerator(); Regex regex = new Regex(_pattern.ToString(), RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase); while (enumerator.MoveNext()) { string current = enumerator.Current; if (regex.IsMatch(current)) { lock (CacheLockbox.GetInternalLock(current)) { InternalCallback(current); continue; } } } }, pattern); }
internal static object InternalCallback(string key) { CacheEntry cacheEntry = CacheLockbox.GetCacheEntry(key); if (cacheEntry == null) { return(null); } CacheLoaderDelegate cacheLoader = cacheEntry.CacheLoader; if (cacheLoader == null) { return(null); } object obj2 = null; try { obj2 = cacheLoader(); } catch (Exception exception) { if (_cacheLoaderErrorDelegate != null) { try { _cacheLoaderErrorDelegate(key, exception); } catch { } } } if (obj2 != null) { Insert(key, obj2, null, (int)cacheEntry.RefreshInterval.TotalSeconds, CacheItemPriority.Normal, new CacheItemRemovedCallback(TCache.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)); }
public static bool ContainsCacheEntry(string key) { return(CacheLockbox.ContainsCacheEntry(key)); }