fastapi-cache icon indicating copy to clipboard operation
fastapi-cache copied to clipboard

flushdb and flushall after clear

Open Martenz opened this issue 1 year ago • 1 comments

Would it be possible to flush also the db and or all when clearing a specific namespace or the entire cache? It seems keys are removed but space is still used in redis db after calling the clear method.

Thanks.

Martenz avatar Oct 03 '23 09:10 Martenz

I made this temporary extent of the backend class to have it done. I guess it can be included in the backend methods. Not sure this is the best way to do it.

class RedisBackendFlush(RedisBackend):
    def __init__(self, redis: Union["Redis[bytes]", "RedisCluster[bytes]"]):
        super().__init__(redis)

    async def flushall(self):
        return await self.redis.flushall()

Martenz avatar Oct 03 '23 13:10 Martenz