|
|
|
@ -17,7 +17,7 @@ class disk_cache: |
|
|
|
caches = [] |
|
|
|
use_lzma = True |
|
|
|
|
|
|
|
def __init__(self, func): |
|
|
|
def __init__(self, func, uses_setup=False): |
|
|
|
if disk_cache.use_lzma: |
|
|
|
self.fname = "{}.{}.dc.lzma".format(func.__module__, func.__name__) |
|
|
|
else: |
|
|
|
@ -25,16 +25,21 @@ class disk_cache: |
|
|
|
|
|
|
|
self.fname = os.path.join(cache_dir, self.fname) |
|
|
|
self.func = func |
|
|
|
self.uses_setup = uses_setup |
|
|
|
self.load_cache() |
|
|
|
disk_cache.caches.append(self) |
|
|
|
|
|
|
|
def __call__(self, *args, **kwargs): |
|
|
|
if self.uses_setup: |
|
|
|
setup = kwargs.pop("__setup__", None) |
|
|
|
key = make_key(*args, **kwargs) |
|
|
|
try: |
|
|
|
res = self.cache[key] |
|
|
|
return res |
|
|
|
except KeyError: |
|
|
|
self.fresh = True |
|
|
|
if self.uses_setup: |
|
|
|
kwargs["__setup__"] = setup |
|
|
|
res = self.func(*args, **kwargs) |
|
|
|
self.cache[key] = res |
|
|
|
return res |
|
|
|
|