Skip to content

Commit 87419a8

Browse files
author
Ram Rachum
committed
-
1 parent 08534f7 commit 87419a8

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

garlicsim/garlicsim/general_misc/caching/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
'''Defines various caching tools.'''
55

6+
# todo: examine thread-safety
67

78
from .cache import cache
89
from .cached_type import CachedType

garlicsim/garlicsim/general_misc/caching/cache.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
See its documentation for more details.
88
'''
99
# blocktodo: test double-caching of function
10+
# todo: examine thread-safety
1011

1112
import 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

Comments
 (0)