In FastAPI I have an endpoint:
from aiocache import Cache, cached
@router.get("/id/{user_id}/permissions")
@cached(ttl=30, cache=Cache.MEMORY)
async def get_permissions(user_id: UUID4) -> list[Permissions]:
And then in my unit test, I want to clear the cache.
I have tried recreating the cache with a namespace, key. Currently I have:
from my_module import get_permissions
my_cache = get_permissions.cache
await my_cache.clear()
I have tried every imaginable combination. But I cannot get this asynchronous test to clear my cache. Any ideas? What am I doing wrong? Could it be there are in different processes?
Well, I've done the same as you, since your question is in an async context, perhaps is your test setup? Here is a sample that works using the pytest and pytest_asyncio plugins.