Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FSL
fslpy
Commits
e74271e1
Commit
e74271e1
authored
6 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
ENH: memoize.skipUnchanged has an invalidate "method"
parent
a4ac1921
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/utils/memoize.py
+18
-0
18 additions, 0 deletions
fsl/utils/memoize.py
with
18 additions
and
0 deletions
fsl/utils/memoize.py
+
18
−
0
View file @
e74271e1
...
@@ -205,6 +205,18 @@ def skipUnchanged(func):
...
@@ -205,6 +205,18 @@ def skipUnchanged(func):
*not* called. If the given value is different from the cached value (or
*not* called. If the given value is different from the cached value (or
there is no value), the decorated function is called.
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
.. note:: This decorator ignores the return value of the decorated
function.
function.
...
@@ -216,6 +228,10 @@ def skipUnchanged(func):
...
@@ -216,6 +228,10 @@ def skipUnchanged(func):
cache
=
{}
cache
=
{}
# TODO merge skipUnchanged and Memoize somehow
def
invalidate
():
cache
.
clear
()
def
wrapper
(
name
,
value
,
*
args
,
**
kwargs
):
def
wrapper
(
name
,
value
,
*
args
,
**
kwargs
):
oldVal
=
cache
.
get
(
name
,
None
)
oldVal
=
cache
.
get
(
name
,
None
)
...
@@ -243,6 +259,8 @@ def skipUnchanged(func):
...
@@ -243,6 +259,8 @@ def skipUnchanged(func):
return
True
return
True
wrapper
.
invalidate
=
invalidate
return
wrapper
return
wrapper
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment