This commit is contained in:
Amr Mohammed 2026-09-30 10:29:53 -04:00 • committed by GitHub
commit ca34ce3025
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 37 additions and 0 deletions

View file

@ -41,6 +41,7 @@ from .redis_cluster_cache import RedisClusterCache
from .redis_semantic_cache import RedisSemanticCache
from .s3_cache import S3Cache
_warned_dropped_cache_params: set = set()
if TYPE_CHECKING:
from litellm.rust_bridge.response_cache import NativeCacheRequest, ResponseCacheRuntime
@ -400,6 +401,19 @@ class Cache:
continue # ignore None params
param_value = kwargs[param]
cache_key += f"{param}: {param_value}"
elif (
kwargs[param] is not None
and param not in _warned_dropped_cache_params
and len(_warned_dropped_cache_params) < 100
):
_warned_dropped_cache_params.add(param)
verbose_logger.warning(
"litellm.cache: provider-specific param '%s' is excluded from the cache key by default, "
"so requests differing only in '%s' will return the same cached response. "
"Set litellm.enable_caching_on_provider_specific_optional_params=True to include it in the key.",
param,
param,
)
if is_semantic_cache:
cache_key += self._get_semantic_cache_tenant_scope(kwargs)

View file

@ -24,6 +24,7 @@ import hashlib
import random
import pytest
import logging
import litellm
from litellm import aembedding, completion, embedding
@ -74,6 +75,28 @@ async def test_dual_cache_async_batch_get_cache():
await dual_cache.async_batch_get_cache(keys=["test_value", "test_value_2"])
assert mock_redis_cache.call_count == 1
def test_cache_key_warns_on_dropped_provider_specific_param(caplog):
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")
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)
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():