diff --git a/litellm/caching.py b/litellm/caching.py index 5601fab2fd..59fc0ab672 100644 --- a/litellm/caching.py +++ b/litellm/caching.py @@ -678,7 +678,7 @@ class Cache: if k == "ttl": kwargs["ttl"] = v cached_data = {"timestamp": time.time(), "response": result} - return cache_key, cached_data + return cache_key, cached_data, kwargs else: raise Exception("cache key is None") except Exception as e: @@ -696,7 +696,7 @@ class Cache: None """ try: - cache_key, cached_data = self._add_cache_logic( + cache_key, cached_data, kwargs = self._add_cache_logic( result=result, *args, **kwargs ) self.cache.set_cache(cache_key, cached_data, **kwargs) @@ -710,7 +710,7 @@ class Cache: Async implementation of add_cache """ try: - cache_key, cached_data = self._add_cache_logic( + cache_key, cached_data, kwargs = self._add_cache_logic( result=result, *args, **kwargs ) await self.cache.async_set_cache(cache_key, cached_data, **kwargs) diff --git a/litellm/tests/test_caching.py b/litellm/tests/test_caching.py index 3250a26215..695ad931a2 100644 --- a/litellm/tests/test_caching.py +++ b/litellm/tests/test_caching.py @@ -109,10 +109,7 @@ def test_caching_with_cache_controls(): ) print(f"response1: {response1}") print(f"response2: {response2}") - assert ( - response2["choices"][0]["message"]["content"] - == response1["choices"][0]["message"]["content"] - ) + assert response2["id"] == response1["id"] except Exception as e: print(f"error occurred: {traceback.format_exc()}") pytest.fail(f"Error occurred: {e}") diff --git a/litellm/utils.py b/litellm/utils.py index 6059cdf85a..3fee13937a 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -2029,7 +2029,11 @@ def client(original_function): # if caching is false or cache["no-cache"]==True, don't run this if ( ( - (kwargs.get("caching", None) is None and litellm.cache is not None) + ( + kwargs.get("caching", None) is None + and kwargs.get("cache", None) is None + and litellm.cache is not None + ) or kwargs.get("caching", False) == True or ( kwargs.get("cache", None) is not None