Пример #1
0
        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);
        }
Пример #2
0
 private static void OnFlushEvent(FlushEventArgs args)
 {
     using (GlobalInitializerFacade.CoreLockScope)
     {
         _coreInitialized = false;
     }
 }
Пример #3
0
        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);
            }
        }
Пример #4
0
        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);
            }
        }
Пример #5
0
        /// <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);
        }
Пример #6
0
        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);
                        }
                    }
                }
            }
        }
Пример #7
0
        protected override void OnOutputStreamFlushing(FlushEventArgs args)
        {
            if (!this.HeaderSent)
            {
                args            = new FlushEventArgs(this.SerializeHeaders() + args.Data);
                this.HeaderSent = true;
            }

            base.OnOutputStreamFlushing(args);
        }
Пример #8
0
        public void Clear()
        {
            foreach (var pair in _cache)
            {
                var args = new FlushEventArgs(pair.Key, pair.Value.Value);

                RaiseFlushEvent?.Invoke(this, args);
            }

            _cache.Clear();
        }
Пример #9
0
        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();
        }
Пример #10
0
        /// <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);
                }
            }
        }
Пример #11
0
 private static void OnFlushEvent(FlushEventArgs args)
 {
     _workflowFacade.Flush();
 }
 private static void OnFlushEvent(FlushEventArgs args)
 {
     _implementation.OnFlush();
 }
Пример #13
0
 private static void OnFlushEvent(FlushEventArgs args)
 {
     using (GlobalInitializerFacade.CoreLockScope)
     {
         _coreInitialized = false;
     }
 }
Пример #14
0
 private static void OnFlushEvent(FlushEventArgs args)
 {
     Flush();
 }
 private static void OnFlushEvent(FlushEventArgs args)
 {
     _metaFunctionProviderRegistry.Flush();
 }
Пример #16
0
 private static void OnFlushEvent(FlushEventArgs args)
 {
     Flush();
     ReadSettings();
 }
 private void OnFlush(FlushEventArgs args)
 {
     _packageDescriptions = null;
 }
Пример #18
0
 private static void OnFlushEvent(FlushEventArgs args)
 {
     _metaFunctionProviderRegistry.Flush();
 }
Пример #19
0
 private static void OnFlushEvent(FlushEventArgs args)
 {
     _hookingFacade.Flush();
 }
Пример #20
0
 private static void OnFlushEvent(FlushEventArgs args)
 {
     Interlocked.Increment(ref _flushCounter);
     _subscribedTo = new Hashset <Type>();
 }
 private static void OnFlushEvent(FlushEventArgs args)
 {
     _externalFileChangeActions.Clear();
 }
 private void OnFlush(FlushEventArgs args)
 {
     _packageDescriptions = null;
 }
Пример #23
0
 private static void OnFlushEvent(FlushEventArgs args)
 {
     Interlocked.Increment(ref _flushCounter);
     _subscribedTo = new Hashset<Type>();
 }
Пример #24
0
 private static void OnFlushEvent(FlushEventArgs args)
 {
     _hookingFacade.Flush();
 }
Пример #25
0
 private static void OnFlushEvent(FlushEventArgs args)
 {
     Flush();
 }
 private static void OnFlushEvent(FlushEventArgs args)
 {
     _externalFileChangeActions.Clear();
 }
Пример #27
0
 private static void OnFlushEvent(FlushEventArgs args)
 {
     _implementation.OnFlush();
 }
Пример #28
0
 private static void OnFlushEvent(FlushEventArgs args)
 {
     _workflowFacade.Flush();
 }