Skip to content

Conversation

@Mdaadm
Copy link

@Mdaadm Mdaadm commented Feb 21, 2025

Fixes #451

calling

FastAPICache.clear(key="value")

method generates

namespace = cls._prefix + (":" + namespace if namespace else "")

even if key is passed. It then goes to

cls._backend.clear(namespace, key)

where key is never used because of this if-else statement:

if namespace:
    lua = f"for i, name in ipairs(redis.call('KEYS', '{namespace}:*')) do redis.call('DEL', name); end"
    return await self.redis.eval(lua, numkeys=0)  # type: ignore[union-attr,no-any-return]
elif key:
    return await self.redis.delete(key)  # type: ignore[union-attr]
return 0

Same for inmemory backend realisation.

With proposed changes clearing cache by key will work correctly, without clearing whole namespace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't clear Redis by key if a prefix has been set

1 participant