77See its documentation for more details.
88'''
99# blocktodo: test double-caching of function
10+ # todo: examine thread-safety
1011
1112import functools
1213
@@ -73,13 +74,6 @@ def cached(function, *args, **kwargs):
7374 cached ._cache [sleek_call_args ] = value = \
7475 function (* args , ** kwargs )
7576 return value
76-
77- cached ._cache = cache_dict
78- cached .is_cached = True
79-
80- result = decorator_tools .decorator (cached , function )
81- result .cache_clear = cached ._cache .clear
82- return result
8377
8478 else : # max_size < infinity
8579
@@ -103,11 +97,15 @@ def cached(function, *args, **kwargs):
10397 cached ._cache .popitem (last = False )
10498 return value
10599
106- cached ._cache = cache_dict
107- cached .is_cached = True
100+ cached ._cache = cache_dict
101+ cached .is_cached = True
102+
103+ def cache_clear ():
104+ '''Clear the cache, deleting all saved results.'''
105+ cache .clear ()
108106
109- result = decorator_tools .decorator (cached , function )
110- result .cache_clear = cached ._cache .clear
111- return result
107+ result = decorator_tools .decorator (cached , function )
108+ result .cache_clear = cached ._cache .clear
109+ return result
112110
113111 return decorator
0 commit comments