Callback for cache access
See original GitHub issueI’m trying to add Prometheus metrics around my cache use. The metrics I’d like are:
- count of accesses
- count of hits
- count of evictions
Hit rate can then be hits / accesses, and eviction rate evictions / accesses.
This is what I have now;
// ... init metrics counters
return memoizee(myFunction, {
max: 250,
dispose() {
evictionCounter.inc()
},
})
Having another callback, in addition to dispose which gets called after every access and has (hit: boolean) as the parameter would be really useful.
For example:
function onAccess(hit: boolean) {
accessCounter.inc()
if (hit) {
hitCounter.inc()
}
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Caching Access Checks - Win32 apps | Microsoft Learn
When an application performs an access check by calling the AuthzAccessCheck function, the results of that access check can be cached.
Read more >Background Callback Caching | Dash for Python Documentation
Background callbacks support caching callback function results, which saves and reuses the results of the function if it is called multiple times with...
Read more >How to avoid caching on access callbacks? - Drupal Answers
I am using Views Access Callback module to set my custom callback access check. I have written a custom module and implemented the...
Read more >CBFS Cache | Cache Library - Callback Technologies
CBFS Cache is a completely self-contained file caching solution. Just insert it between your application's local and remote data access logic, and it...
Read more >Cache a value fetched from a listener callback - Stack Overflow
When doStuff() is called for the first time, cacheStorage is empty, so getStatePromise() will fetch the State object, populate the cache, and ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

That solution seems to work, thanks. For reference, here is what I did:
To get the types to work I also did this:
Great, thank you. I’ll have a look at the extensions.