flask-cache
flask-cache copied to clipboard
Pass decorated functions arguments into unless()
There are times that we only want to memoize in certain circumstances, which I'm assuming is the reason why unless() exists.
It would be nice for unless() to decide whether to memoize depending on the arguments passed into the decorated function. This is especially nice if the decorated function is an object method (since the first *arg is self).
For example, let's say we want to only memoize if self.baz is a certain value.:
class Foo(object):
def __init__(self, baz):
self.baz = baz
@cached.memoize(unless=?)
def bar(self):
return "something"
Do you think there would be any interest in passing the decorated function's args/kwargs into unless()?
The pull request #95 kind of illustrates what I was thinking. It would be backwards compatible for people that have implemented an unless() without arguments and also the new signature with unless(f, _args, *_kwargs).