-
-
Save lgolubyev/c2a6b4a89d715921ae4028a09f7f2d41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// when using `services.AddMemoryCache(options => options.TrackStatistics = true);` to instantiate | |
[EventSource(Name = "Microsoft-Extensions-Caching-Memory")] | |
internal sealed class CachingEventSource : EventSource | |
{ | |
public CachingEventSource(IMemoryCache memoryCache) { _memoryCache = memoryCache; } | |
protected override void OnEventCommand(EventCommandEventArgs command) | |
{ | |
if (command.Command == EventCommand.Enable) | |
{ | |
if (_cacheHitsCounter == null) | |
{ | |
_cacheHitsCounter = new PollingCounter("cache-hits", this, () => | |
_memoryCache.GetCurrentStatistics().CacheHits) | |
{ | |
DisplayName = "Cache hits", | |
}; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment