Run callback after function with cache hit/miss result
Hey, I was wondering if there was a mechanism to run a function after the cached function that identifies if the value was in the cache or not. For example if I wanted to log if the request was a cache hit or miss, and send that statistic to a monitoring service, to get better insight if my calls are mostly cached or not.
Wasn't sure if it's in scope for this project, or how else I could determine if the cache had the value or not
I already thought about adding some metrics, although nothing specific. Adding callbacks is definitely not the way to do it, though.
I thought about a property on the Flask-Caching object, but what this property should hold is still a big question mark in my head. If thatʼs not feasible we may also, well, cache it under a reserved key, but that would skew the metrics and put extra load on the cache backend.
Flask Signals are built for this.
@alanhamlett yes they are, but in the case of caching it might introduce unnecessary overhead. Thatʼs why i said if the use case is collecting metrics, it should be done differently.
Just saw your comment after creating my PR. How about I add a config to enable/disable signals so the user can decide if they don't mind the extra overhead?
Thatʼs exactly what i was thinking when i saw your PR ☺
Signals sound like a great solution for this usecase