Open jftsang opened 4 years ago
Use diskcache to cache images, with the option to refresh. This pattern doesn't quite work...
from diskcache import Cache
cache = Cache()
def fib(x: int, refresh: bool = False) -> int:
if refresh:
cache.evict(tag="fib") # but can we evict just a single argument?
return _fib(x)
@cache.memoize(tag="fib")
def _fib(x: int) -> int:
print(f"Evaluating F_{x}")
if x == 0 or x == 1:
return x
return fib(x-1) + fib(x-2)
There is currently no way of clearing the cache (except through manually deleting files in that directory), which means that it could get rather large after a while.
Possible solution is to have a cronjob that removes files older than 3 days.