diff --git a/fastapi_cache/__init__.py b/fastapi_cache/__init__.py index 1c85203..af13fa1 100644 --- a/fastapi_cache/__init__.py +++ b/fastapi_cache/__init__.py @@ -99,5 +99,6 @@ async def clear( assert ( # noqa: S101 cls._backend and cls._prefix is not None ), "You must call init first!" - namespace = cls._prefix + (":" + namespace if namespace else "") + if namespace is not None or key is None: + namespace = cls._prefix + (":" + namespace if namespace else "") return await cls._backend.clear(namespace, key)