/// <summary> /// Called when an item gets added to the cache. /// </summary> /// <param name="item">The item.</param> /// <exception cref="System.ArgumentNullException">If item is null.</exception> public void OnAdd(ICacheItem <TKey, TValue> item) { if (!_isStatsEnabled) { return; } NotNull(item, nameof(item)); _counter.Increment(CacheStatsCounterType.AddCalls); _counter.Increment(CacheStatsCounterType.Items); }
/// <summary> /// Called when the cache got cleared. /// </summary> public void OnClear() { if (!_isStatsEnabled) { return; } // clear needs a lock, otherwise we might mess up the overall counts foreach (var key in _counters.Keys) { CacheStatsCounter counter = null; if (_counters.TryGetValue(key, out counter)) { counter.Set(CacheStatsCounterType.Items, 0L); counter.Increment(CacheStatsCounterType.ClearCalls); } } }