Skip to content
Snippets Groups Projects
Commit e74271e1 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

ENH: memoize.skipUnchanged has an invalidate "method"

parent a4ac1921
No related branches found
No related tags found
No related merge requests found
......@@ -205,6 +205,18 @@ def skipUnchanged(func):
*not* called. If the given value is different from the cached value (or
there is no value), the decorated function is called.
The ``invalidate`` method may be called on a ``skipUnchanged``-decorated
function to clear the internal cache. For example::
@skipUnchanged
def setval(name, value):
# ...
# ...
setval.invalidate()
.. note:: This decorator ignores the return value of the decorated
function.
......@@ -216,6 +228,10 @@ def skipUnchanged(func):
cache = {}
# TODO merge skipUnchanged and Memoize somehow
def invalidate():
cache.clear()
def wrapper(name, value, *args, **kwargs):
oldVal = cache.get(name, None)
......@@ -243,6 +259,8 @@ def skipUnchanged(func):
return True
wrapper.invalidate = invalidate
return wrapper
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment