public T Execute() { IAcquireContext parentContext = _cacheContextAccessor.Current; try { if (parentContext == null) { _cacheContextAccessor.Current = new SimpleAcquireContext(AddToken); } return(_function()); } finally { if (parentContext == null) { _cacheContextAccessor.Current = parentContext; } } }
private CacheEntry CreateEntry(TKey k, Func <AcquireContext <TKey>, TResult> acquire) { var entry = new CacheEntry(); var context = new AcquireContext <TKey>(k, entry.AddToken); IAcquireContext parentContext = null; try { // Push context parentContext = _cacheContextAccessor.Current; _cacheContextAccessor.Current = context; entry.Result = acquire(context); } finally { // Pop context _cacheContextAccessor.Current = parentContext; } entry.CompactTokens(); return(entry); }
private static CacheEntry CreateEntry(TKey k, Func <AcquireContext <TKey>, TResult> acquire) { var entry = new CacheEntry { Tokens = new List <IVolatileToken>() }; var context = new AcquireContext <TKey>(k, volatileItem => entry.Tokens.Add(volatileItem)); IAcquireContext parentContext = null; try { // Push context parentContext = CacheAquireContext.ThreadInstance; CacheAquireContext.ThreadInstance = context; entry.Result = acquire(context); } finally { // Pop context CacheAquireContext.ThreadInstance = parentContext; } return(entry); }
/// <summary> /// Execute task and collect eventual volatile tokens /// </summary> public T Execute() { IAcquireContext parentContext = cacheContextAccessor.Current; try { // Push context if (parentContext == null) { cacheContextAccessor.Current = new SimpleAcquireContext(AddToken); } // Execute lambda return(function()); } finally { // Pop context if (parentContext == null) { cacheContextAccessor.Current = null; } } }
private CacheEntry CreateEntry(TKey k, Func <AcquireContext <TKey>, TResult> acquire) { var entry = new CacheEntry(); var context = new AcquireContext <TKey>(k, entry.AddToken); IAcquireContext parentContext = null; try { // Push context parentContext = _cacheContextAccessor.Current; _cacheContextAccessor.Current = context; entry.Result = acquire(context); //创建缓存 var flag = _client.ExecuteStore(StoreMode.Set, k.ToString(), entry); } finally { // Pop context _cacheContextAccessor.Current = parentContext; } entry.CompactTokens(); return(entry); }
public void MonitorConfigurationChanged(IAcquireContext acquireContext) { acquireContext.Monitor(_signals.When(_configurationChangedSignal)); }
public void MonitorCacheEmptied(IAcquireContext acquireContext) { acquireContext.Monitor(_signals.When(_cacheEmptiedSignal)); }
public void MonitorCacheEmptied(IAcquireContext acquireContext) { acquireContext.Monitor(_signals.When(_cacheEmptiedSignal)); }
public void MonitorConfigurationChanged(IAcquireContext acquireContext) { acquireContext.Monitor(_signals.When(_configurationChangedSignal)); }