private static void InitListener(string listenerKey, int expiredInterval, string updateListentKey, int updateInterval) { if (enableUpdateListent && _cacheUpdateListener == null) { _cacheUpdateListener = new CacheListener(updateListentKey, updateInterval, (key, value, reason) => { try { if (!_isRunning) { _isRunning = true; TraceLog.WriteLine("{0} Cache sync to storage start...", DateTime.Now.ToString("HH:mm:ss")); UpdateNotify(true); TraceLog.WriteLine("{0} Cache sync to storage end.", DateTime.Now.ToString("HH:mm:ss")); _isRunning = false; } else { TraceLog.WriteLine("{0} Cache sync to storage doing...", DateTime.Now.ToString("HH:mm:ss")); } } catch (Exception ex) { TraceLog.WriteError("Cache manager timing error:{0}", ex); } }); } if (_cacheExpiredListener == null) { _cacheExpiredListener = new CacheListener(listenerKey, expiredInterval, (key, value, reason) => { if (reason == CacheRemovedReason.Expired) { try { _readonlyPools.DisposeCache(); _writePools.DisposeCache(); TraceLog.WriteLine("{0} Clear expired cache end.", DateTime.Now.ToString("HH:mm:ss")); } catch (Exception ex) { TraceLog.WriteError("Cache manager timing error:{0}", ex); } } }); } }
private static void InitListener(string listenerKey, int expiredInterval, string updateListentKey, int updateInterval) { if (enableUpdateListent && _cacheUpdateListener == null) { _cacheUpdateListener = new CacheListener(updateListentKey, updateInterval, (key, value, reason) => { try { if (!_isRunning) { _isRunning = true; TraceLog.ReleaseWrite("缓存延迟更新执行开始"); UpdateNotify(true); TraceLog.ReleaseWrite("缓存延迟更新执行结束"); _isRunning = false; } else { TraceLog.ReleaseWrite("缓存延迟更新正在执行中..."); } } catch (Exception ex) { TraceLog.WriteError("Cache manager timing error:{0}", ex); } }); } if (_cacheExpiredListener == null) { _cacheExpiredListener = new CacheListener(listenerKey, expiredInterval, (key, value, reason) => { if (reason == CacheRemovedReason.Expired) { try { _readonlyPools.DisposeCache(); _writePools.DisposeCache(); TraceLog.ReleaseWrite("清理过期缓存结束..."); } catch (Exception ex) { TraceLog.WriteError("Cache manager timing error:{0}", ex); } } }); } }