This doesn’t look well documented, but there’s an issue that trackes the problem a solution.
I made it a bit simpler to use this way:
def timed_cache(expires_after_hours: int = 6):
def _expiring_cache(func):
@wraps(func)
def memory(*args, **kwargs):
home_var = os.getenv("HOME")
assert home_var, "$HOME is not set"
cache_dir = Path(home_var) / Path(".cache") / Path("themes")
return Memory(
cache_dir,
verbose=0,
).cache(
func, cache_validation_callback=expires_after(seconds=1)#hours=expires_after_hours)
)(*args, **kwargs)
return memory
return _expiring_cache
And then you can use it like
@timed_cache() # use 6 hrs default
def expensive_func():
pass