public void UnregisterRemoteCacheDependency(string cacheKey) { if (!string.IsNullOrEmpty(cacheKey)) { lock (_remoteCacheKeys) { if (_remoteCacheKeys.ContainsKey(cacheKey)) { CacheKeyStats cacheKeyCounter = _remoteCacheKeys[cacheKey]; if (cacheKeyCounter != null) { cacheKeyCounter.refCount--; if (cacheKeyCounter.refCount == 0) { _remoteCacheKeys.Remove(cacheKey); } } } } lock (_registerCallbackQueue) { ThreadTask registerThread = new ThreadTask(cacheKey, false, true); _registerCallbackQueue.Enqueue(registerThread); Monitor.Pulse(_registerCallbackQueue); } } }
public void RegisterRemoteCacheDependency(string cacheKey) { if (!string.IsNullOrEmpty(cacheKey)) { bool isNewKey = false; lock (_remoteCacheKeys) { if (_remoteCacheKeys.ContainsKey(cacheKey)) { CacheKeyStats cacheStats = _remoteCacheKeys[cacheKey]; if (cacheStats != null) { cacheStats.refCount++; cacheStats.HasExpired = false; } else { cacheStats = new CacheKeyStats(); cacheStats.refCount = 1; cacheStats.HasExpired = false; } } else { CacheKeyStats cacheStats = new CacheKeyStats(); cacheStats.refCount = 1; cacheStats.HasExpired = false; _remoteCacheKeys.Add(cacheKey, cacheStats); isNewKey = true; } } if (isNewKey) { lock (_registerCallbackQueue) { ThreadTask registerThread = new ThreadTask(cacheKey, true, false); _registerCallbackQueue.Enqueue(registerThread); Monitor.Pulse(_registerCallbackQueue); } } } }
private void RegUnRegRemoteCacheDependency() { while (true) { try { if (_registerCallbackQueue.Count > 0) { object cacheKey = null; lock (_registerCallbackQueue) { cacheKey = _registerCallbackQueue.Dequeue(); } if (cacheKey == null) { continue; } ThreadTask threadTask = (ThreadTask)cacheKey; if (threadTask.cacheKey == null) { throw new Exception(" cache key null"); } if (threadTask.register) { try { _cache.RegisterKeyNotificationCallback(threadTask.cacheKey, null, _removeCallback); } catch (Exception e) { SetItemExpiration(cacheKey.ToString(), "Event Registration faliure"); } } else if (threadTask.unRegister) { _cache.UnRegisterKeyNotificationCallback(threadTask.cacheKey, null, _removeCallback); } } else { lock (_registerCallbackQueue) { if (_registerCallbackQueue.Count == 0) { Monitor.Wait(_registerCallbackQueue); } } } } catch (ThreadAbortException t) { break; } catch (ThreadInterruptedException i) { break; } catch (Exception ex) { } } }