Add a post-cache-load hook
It would be practical if there was a way to detect that data was returned from the cache and then do some extra post-processing. My particular use case is caching SQLAlchemy ORM instances which needs to be merged into the session. Currently I am doing something like this:
@region.cache_on_arguments() def _expensive_function(foo, bar): ... def expensive_function(foo, bar): result = _expensive_function(foo, bar) if result not in session: session.merge(result, load=False) return result
This could be reworked as a decorator to be more generic and easier to read, but it still has to do this in-session check and possible merge on every invocation instead of only for cache hits. It would be nice to be able to do this:
def _merge(obj): session.merge(obj, load=False) @region.cache_on_arguments(on_cache_hit=_merge) def _expensive_function(foo, bar): ...