forked from theonlydude/RandomMetroidSolver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache.py
24 lines (21 loc) · 871 Bytes
/
cache.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# the caching decorator for helpers functions
class Cache:
cache = {}
@staticmethod
def reset():
Cache.cache = {}
@staticmethod
def decorator(func):
def _decorator(self):
if func.__name__ in Cache.cache:
# print("cache found for {}: {}".format(func.__name__, Cache.cache[func.__name__]))
# ret = func(self)
# if ret != Cache.cache[func.__name__]:
# print("ERROR: cache ({}) != current ({}) for {}".format(Cache.cache[func.__name__], ret, func.__name__))
return Cache.cache[func.__name__]
else:
ret = func(self)
Cache.cache[func.__name__] = ret
# print("cache added for {}: {}".format(func.__name__, Cache.cache[func.__name__]))
return ret
return _decorator