Is there an easy way to clear the cache?
Sometimes I need to invalidate the cache or need an empty cache in my tests. I didn't see any simple solution to clear it.
Currently im doing it like this:
from cache import AsyncTTL
@AsyncTTL(...)
async def my_function(...):
...
in order to clear the cache I have to this:
my_function.__closure__[1].cell_contents.ttl.clear()
it would be nice to have this function easily accessible like (same as functools.lru):
my_function.clear_cache()
and maybe even have access to the non-wrapped function with:
my_function.__wrapped__
which would be useful to disable cache during tests my mocking the cached function in conftest.py:
@pytest.fixture(auto_use=True)
def no_cache(monkeypatch):
monkeypatch.setattribute(my_module, 'my_function', my_module.my_function.__wrapped__)
Would be a nice improvement if something like this would be implemented :)
Hi! I just ran into the same issue. The PR #23 has a solution.
Thanks @MarijnHoum for adding this feature, will be a great help. Will close this issue when new version is released.
Hi hi! :) Hope you are all well! Any timeframe on the new version? I see the latest doesn't contain the latest changes in main
Seems like this project is in passive state. I've forked this repo and added your issue as new feature there. https://github.com/doubledare704/async-cache already deployed to pypi
@jeremyschiemann @MarijnHoum @durancole