/// <summary> /// Set the hit and miss rate counters to 0. /// </summary> protected internal void ZeroHitCounter(string name) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException(nameof(name)); } PercentageRatePerformanceCounter hitRateCounter; NumberOfItems64PerformanceCounter totalHitsCounter; NumberOfItems64PerformanceCounter totalMissesCounter; hitRateCounter = HitRateCounters.GetOrAdd( name, n => Category.GetPerformanceCounter <PercentageRatePerformanceCounter>(CachePerformanceCounters.HitRateCounterName, name) ); hitRateCounter.Zero(); totalHitsCounter = TotalHitsCounters.GetOrAdd( name, n => Category.GetPerformanceCounter <NumberOfItems64PerformanceCounter>(CachePerformanceCounters.TotalHitsCounterName, name) ); totalHitsCounter.SetValue(0); totalMissesCounter = TotalMissesCounters.GetOrAdd( name, n => Category.GetPerformanceCounter <NumberOfItems64PerformanceCounter>(CachePerformanceCounters.TotalMissesCounterName, name) ); totalMissesCounter.SetValue(0); }
/// <summary> /// Update the cache size counter. /// </summary> protected internal void UpdateHitCounter(string name, long hits, long misses) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException(nameof(name)); } PercentageRatePerformanceCounter hitRateCounter; NumberOfItems64PerformanceCounter totalHitsCounter; NumberOfItems64PerformanceCounter totalMissesCounter; hitRateCounter = HitRateCounters.GetOrAdd( name, n => Category.GetPerformanceCounter <PercentageRatePerformanceCounter>(CachePerformanceCounters.HitRateCounterName, name) ); hitRateCounter.AddHits(hits); hitRateCounter.AddMisses(misses); totalHitsCounter = TotalHitsCounters.GetOrAdd( name, n => Category.GetPerformanceCounter <NumberOfItems64PerformanceCounter>(CachePerformanceCounters.TotalHitsCounterName, name) ); totalHitsCounter.IncrementBy(hits); totalMissesCounter = TotalMissesCounters.GetOrAdd( name, n => Category.GetPerformanceCounter <NumberOfItems64PerformanceCounter>(CachePerformanceCounters.TotalMissesCounterName, name) ); totalMissesCounter.IncrementBy(misses); }