public bool TryGetValue(TKey key, out TValue value) { TimestampedValue result; value = default(TValue); if (cache.TryGetValue(key, out result)) { result.Generation = Interlocked.Increment(ref nextGeneration); var age = DateTime.UtcNow.Subtract(result.WhenLoaded); if (age > requiredFreshness) { if (!cache.TryRemove(key, out result)) { return(false); } if (RaiseFlushEvent == null) { return(false); } var args = new FlushEventArgs(key, result.Value); RaiseFlushEvent(this, args); return(false); } value = result.Value; } else { return(false); } return(true); }
private static void OnFlushEvent(FlushEventArgs args) { using (GlobalInitializerFacade.CoreLockScope) { _coreInitialized = false; } }
private void AdjustSize() { while (cache.Count >= MaximumSize) { long generationToDelete = Interlocked.Increment(ref generationToFree); KeyValuePair <TKey, TimestampedValue> entryToFree = cache.FirstOrDefault(kvp => kvp.Value.Generation == generationToDelete); if (entryToFree.Key == null) { continue; } TKey keyToFree = entryToFree.Key; TimestampedValue old; if (!cache.TryRemove(keyToFree, out old)) { continue; } if (RaiseFlushEvent == null) { continue; } var args = new FlushEventArgs(keyToFree, old.Value); RaiseFlushEvent(this, args); } }
private void AdjustSize() { while (_cache.Count >= MaximumSize) { var generationToDelete = Interlocked.Increment(ref _generationToFree); var entryToFree = _cache.FirstOrDefault(kvp => kvp.Value.Generation == generationToDelete); if (entryToFree.Key == null) { continue; } var keyToFree = entryToFree.Key; if (!_cache.TryRemove(keyToFree, out var old)) { continue; } if (RaiseFlushEvent == null) { continue; } var args = new FlushEventArgs(keyToFree, old.Value); RaiseFlushEvent(this, args); } }
/// <summary> /// 尝试获取缓存值,如果超过 MaxAge,该条目将被惰性清理掉。 /// </summary> /// <param name="key">键</param> /// <param name="value">键</param> /// <returns>是否成功</returns> public bool TryGetValue(TKey key, out TValue value) { value = default; if (_cache.TryGetValue(key, out var result)) { result.Generation = Interlocked.Increment(ref _nextGeneration); var age = DateTime.UtcNow.Subtract(result.WhenLoaded); if (age > _maxAge) { if (!_cache.TryRemove(key, out result)) { return(false); } if (RaiseFlushEvent == null) { return(false); } var args = new FlushEventArgs(key, result.Value); RaiseFlushEvent(this, args); return(false); } value = result.Value; } else { return(false); } return(true); }
private static void OnFlushEvent(FlushEventArgs args) { // Removing all non flush-persistent subscriptions var dictionaries = new[] { _dataBeforeAddEventDictionary, _dataAfterAddEventDictionary, _dataBeforeUpdateEventDictionary, _dataAfterUpdateEventDictionary, _dataDeletedEventDictionary, _dataAfterBuildNewEventDictionary, _storeChangedEventDictionary }; foreach (var dictionary in dictionaries) { foreach (var subscrList in dictionary.GetValues()) { for (int i = subscrList.Count - 1; i >= 0; i--) { if (!subscrList[i].Second) { subscrList.RemoveAt(i); } } } } }
protected override void OnOutputStreamFlushing(FlushEventArgs args) { if (!this.HeaderSent) { args = new FlushEventArgs(this.SerializeHeaders() + args.Data); this.HeaderSent = true; } base.OnOutputStreamFlushing(args); }
public void Clear() { foreach (var pair in _cache) { var args = new FlushEventArgs(pair.Key, pair.Value.Value); RaiseFlushEvent?.Invoke(this, args); } _cache.Clear(); }
public void Clear() { foreach (var pair in cache) { var args = new FlushEventArgs(pair.Key, pair.Value.Value); EventHandler <FlushEventArgs> handler = RaiseFlushEvent; if (handler == null) { continue; } handler(this, args); } cache.Clear(); }
/// <summary> /// Remove all expired value from the LRU instance. /// </summary> public void RemoveExpired() { var now = DateTime.UtcNow; var toRemove = new List <TKey>(); foreach (var entry in this.cache) { var age = DateTime.UtcNow.Subtract(entry.Value.WhenLoaded); if (age > requiredFreshness) { toRemove.Add(entry.Key); } } foreach (var key in toRemove) { if (cache.TryRemove(key, out var result) && RaiseFlushEvent != null) { var args = new FlushEventArgs(key, result.Value); RaiseFlushEvent(this, args); } } }
private static void OnFlushEvent(FlushEventArgs args) { _workflowFacade.Flush(); }
private static void OnFlushEvent(FlushEventArgs args) { _implementation.OnFlush(); }
private static void OnFlushEvent(FlushEventArgs args) { Flush(); }
private static void OnFlushEvent(FlushEventArgs args) { _metaFunctionProviderRegistry.Flush(); }
private static void OnFlushEvent(FlushEventArgs args) { Flush(); ReadSettings(); }
private void OnFlush(FlushEventArgs args) { _packageDescriptions = null; }
private static void OnFlushEvent(FlushEventArgs args) { _hookingFacade.Flush(); }
private static void OnFlushEvent(FlushEventArgs args) { Interlocked.Increment(ref _flushCounter); _subscribedTo = new Hashset <Type>(); }
private static void OnFlushEvent(FlushEventArgs args) { _externalFileChangeActions.Clear(); }
private static void OnFlushEvent(FlushEventArgs args) { Interlocked.Increment(ref _flushCounter); _subscribedTo = new Hashset<Type>(); }