long2ice / fastapi-cache

fastapi-cache is a tool to cache fastapi response and function result, with backends support redis and memcached.
https://github.com/long2ice/fastapi-cache
Apache License 2.0
1.39k stars 168 forks source link

flushdb and flushall after clear #314

Open Martenz opened 1 year ago

Martenz commented 1 year ago

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 commented 1 year ago

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()