before trying to build this out, I wanted to propose these extensions to
If these values are set, before returning the value from the cache it will be passed into the appropriate function as a filter (or a notification).
if GET and callback_get_fn: value = callback_get_fn(value) elif CREATE and callback_create_fn: value = callback_create_fn(value) return value
In some ways this is similar to a proxy, however this pattern would give a lot more flexibility when the cache generating functions have 'byproducts' of setting up miscellaneous data
Consider this example:
def expensive_function(self): self.foo = 'bar' return (1, 2) def outer(self, args): @cache_on_arguments def inner(): (a, b) = self.expensive_function() return (a, b) (a, b) = inner(args)
on the first run, self.foo is set; on the second run it is not.
when migrating functions to use dogpile, a lot of issues like this creep up. While the proper route is to avoid this pattern, that can take a lot of rewriting. If there was a mechanism such as a callback that could be used to derive that the value is cached -- then it would be relatively simple to write a few lines of code to ensure parity with whatever environment an uncached data generation would have created.