Skip to content

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

Open
@dkudeki

Description

@dkudeki

Hi, I ran into an issue where any calls to FastAPICache.clear(key="value") would not work for any given value passed to key. It turns out that even if you don't pass a namespace to the clear function, if you have initialized the connection with a prefix, that prefix is then used to create a namespace:

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

That namespace is then passed along with the key to the Redis clear function, where it supersedes the key that you explicitly are trying to clear, and the clear function is run on the prefix-generated namespace instead.

For my purposes it was simple enough to just drop the prefix altogether, but logically initializing the connection with a prefix shouldn't render clearing by key unusable like it is now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds-triageNeeds to be reviewed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions