Cache invalidation for class or instance methods
When attempting to invalidate or set a value for a class or instance method that's being cached via
CacheRegion.cache_on_arguments, the first argument passed to the decorated function's
set methods is ignored. For example, if I have
class Foo(object): @cache.cache_on_arguments() def do_something(self, text): return text + 'dummy'
then if one wants to clear or set the cache for this method, they need to do this:
foo = Foo() cached = foo.do_something('asdf') foo.do_something.invalidate(anything_goes, 'asdf') foo.do_something.set('value', anything_goes, 'asdf')
as the first argument passed into either function is ignored as part of the cache key. This is probably expected behaviour for now, but I think the situation should be documented either way.
Since the first argument going into those invalidate/set is ignored regardless by the key generator, I think it would be easier to have the key generator use all arguments if the decorated method belongs to a class or instance. This would be far less prone to error as I've found when trying to clear such a cached method & forgetting the first argument.