You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
FastAPICache.Clear(namespace...) does not work with custom key_builder #571
I don't think this is a bug, clear(namespace=...) works a bit differently than it might seem. It doesn't match your literal key string, it clears based on a prefix + namespace pattern, which is meant for clearing groups of keys that share a generated prefix, like when you're using the default key builder.
Since your custom key_builder returns the exact literal key, the simpler fix is to clear it directly by key instead:
Activity
hosamk92 commentedon Jul 28, 2026
Hello @Nickopusan13
I don't think this is a bug,
clear(namespace=...)works a bit differently than it might seem. It doesn't match your literal key string, it clears based on a prefix + namespace pattern, which is meant for clearing groups of keys that share a generated prefix, like when you're using the default key builder.Since your custom key_builder returns the exact literal key, the simpler fix is to clear it directly by key instead:
That should give you the same result as your redis_client.delete(...) workaround.
If you would like to use it with namespace you could use the following:
When using namespace in clear it woul clear all keys that starts by the namespace.