Closed PureKrome closed 5 years ago
If you are using the default MemoryCache implementation of ObjectCache as the underlying cache store then it already has counters built in for this kind of thing. Documentation is not great but this SO post is a start https://stackoverflow.com/q/20059000/3140853
yeah - I read that post yesterday too :(
You could try https://docs.microsoft.com/en-us/dotnet/framework/debug-trace-profile/runtime-profiling#reading-and-creating-performance-counters-programmatically Failing that I would inherit a new cache service from CachingService and add some stats/counters of you own.
Afraid I don't have to build this into the library as I don't have a need for perf counters but nothing stopping you forking the project and adding your own.
Hi @alastairtree
I'm trying to leverage LazyCache but to get some stats on the number of hits/misses in some time frame.
So lets say: given a 1 hour window, how many hits/misses.
First, what's the start of the 1 hour window? is it
DateTime.Now
for the first time this piece of code has ran? (think multiple web requests at the same time, too).Then, how could we increment two different cache keys? I'm assuming that the miss ends up calling the lazy delegate method, so that's not tooo bad. But I still don't know where I could store a counter for misses that would reset (evicted?) after an hour.
Then to the hits! The
GetOrAddAsync
will just return something ... a counter? which i then need to thread-safe increment and THEN reset after an hour again.So - tough problem to solve I think :(
Could you offer any ideas here how LazyCache might be able to leverage some of this?
EDIT: Oh! forgot to mention some reason/scenario also -> at the end of each 60 mins, I was going to send a logging message that reports the cache hit/miss ratio for the last hour. Then reset the hit/miss counters.
So then we can review the logs to see some of the stats.