Beispiel #1
0
        public CounterProvider(CounterFinder finder)
        {
            //
            // Cache strategy
            // key: performance counter category, value: Counter Monitor
            // key: performance counter category + performance counter instance, value: list of performance counters
            // Cache stores one counter monitor per performance counter category
            // When performance counters are requested they are added to the monitor for their category and then cached under category + instance
            //     for quick retrieval and lifetime management
            _cache = new MemoryCache(new MemoryCacheOptions()
            {
                ExpirationScanFrequency = CacheExpiration,
                CompactOnMemoryPressure = false
            });

            _counterFinder = finder;

            _concurrentCacheHelper = new ConcurrentCacheHelper(_cache);

            _cacheEvicter = new Timer(TimerCallback, null, ScanFrequency, ScanFrequency);
        }
Beispiel #2
0
        public void Dispose()
        {
            //
            // Evict the entire cache to trigger handling of disposable resources
            _cache.Compact(100);

            if (_cacheEvicter != null)
            {
                _cacheEvicter.Dispose();
                _cacheEvicter = null;
            }

            if (_cache != null)
            {
                _cache.Dispose();
                _cache = null;
            }

            if (_concurrentCacheHelper != null)
            {
                _concurrentCacheHelper.Dispose();
                _concurrentCacheHelper = null;
            }
        }