From c1f79fdf862a531761162be1e04a64893b4e5384 Mon Sep 17 00:00:00 2001 From: Amr Mohammed Date: Sun, 27 Sep 2026 16:30:31 +0300 Subject: [PATCH] refactor(caching): remove redundant comments, restore warning-set state in test --- litellm/caching/caching.py | 4 ---- tests/local_testing/test_caching.py | 33 ++++++++++++----------------- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/litellm/caching/caching.py b/litellm/caching/caching.py index 50b29830f31..088922046e1 100644 --- a/litellm/caching/caching.py +++ b/litellm/caching/caching.py @@ -394,10 +394,6 @@ class Cache: param_value = kwargs[param] cache_key += f"{param}: {param_value}" elif kwargs[param] is not None and param not in _warned_dropped_cache_params: - # Provider-specific param (e.g. ollama num_ctx) is being excluded - # from the cache key. Two requests differing only in this param - # will collide and the second gets the first's cached response. - # Warn once per param; set enable_caching_on_provider_specific_optional_params=True to include it. _warned_dropped_cache_params.add(param) verbose_logger.warning( "litellm.cache: provider-specific param '%s' is excluded from the cache key by default, " diff --git a/tests/local_testing/test_caching.py b/tests/local_testing/test_caching.py index c6eda589096..8f809df457a 100644 --- a/tests/local_testing/test_caching.py +++ b/tests/local_testing/test_caching.py @@ -78,32 +78,25 @@ async def test_dual_cache_async_batch_get_cache(): def test_cache_key_warns_on_dropped_provider_specific_param(caplog): - """Provider-specific params dropped from the cache key (default flag) should - emit a one-time warning. Regression for #42400.""" import litellm from litellm.caching.caching import Cache, _warned_dropped_cache_params litellm.enable_caching_on_provider_specific_optional_params = False - _warned_dropped_cache_params.discard("num_ctx") # reset in case another test warned + _warned_dropped_cache_params.discard("num_ctx") cache = Cache() + try: + with caplog.at_level(logging.WARNING): + cache.get_cache_key(model="ollama/llama3.2", + messages=[{"role": "user", "content": "hello"}], num_ctx=2048) + assert any("num_ctx" in r.message for r in caplog.records) - with caplog.at_level(logging.WARNING): - cache.get_cache_key( - model="ollama/llama3.2", - messages=[{"role": "user", "content": "hello"}], - num_ctx=2048, - ) - assert any("num_ctx" in r.message for r in caplog.records) - - # second call must NOT warn again (one-time behavior) - caplog.clear() - with caplog.at_level(logging.WARNING): - cache.get_cache_key( - model="ollama/llama3.2", - messages=[{"role": "user", "content": "hello"}], - num_ctx=4096, - ) - assert not any("num_ctx" in r.message for r in caplog.records) + caplog.clear() + with caplog.at_level(logging.WARNING): + cache.get_cache_key(model="ollama/llama3.2", + messages=[{"role": "user", "content": "hello"}], num_ctx=4096) + assert not any("num_ctx" in r.message for r in caplog.records) + finally: + _warned_dropped_cache_params.discard("num_ctx") def test_dual_cache_batch_get_cache():