From 7c72cc0ec9d9fd2de3069af0cdc9a0dfe6c2f91b Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Thu, 14 Mar 2024 13:35:17 -0700 Subject: [PATCH] fix(caching.py): support redis caching with namespaces --- litellm/caching.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/litellm/caching.py b/litellm/caching.py index 33a18b8c1c..9df95f199e 100644 --- a/litellm/caching.py +++ b/litellm/caching.py @@ -798,6 +798,7 @@ class Cache: host: Optional[str] = None, port: Optional[str] = None, password: Optional[str] = None, + namespace: Optional[str] = None, similarity_threshold: Optional[float] = None, supported_call_types: Optional[ List[ @@ -890,6 +891,7 @@ class Cache: litellm._async_success_callback.append("cache") self.supported_call_types = supported_call_types # default to ["completion", "acompletion", "embedding", "aembedding"] self.type = type + self.namespace = namespace def get_cache_key(self, *args, **kwargs): """ @@ -996,6 +998,9 @@ class Cache: # Hexadecimal representation of the hash hash_hex = hash_object.hexdigest() print_verbose(f"Hashed cache key (SHA-256): {hash_hex}") + if self.namespace is not None: + hash_hex = f"{self.namespace}:{hash_hex}" + print_verbose(f"Hashed Key with Namespace: {hash_hex}") return hash_hex def generate_streaming_content(self, content):