litellm/tests/test_litellm/test_prompt_caching_cache.py
ByteWise 14b4e9c0c3 fix(router): respect prompt cache affinity ttl
Derive the router affinity cache TTL from the cacheable prompt prefix so one-hour ephemeral cache hints stay routable for their advertised lifetime instead of expiring after the previous five-minute default.

Related: BerriAI/litellm#28427

Tested: python -m pytest tests/router_unit_tests/test_router_prompt_caching.py -q; python -m pytest tests/test_litellm/test_prompt_caching_cache.py -q; python -m ruff check litellm/router_utils/prompt_caching_cache.py tests/router_unit_tests/test_router_prompt_caching.py tests/test_litellm/test_prompt_caching_cache.py; python -m black litellm/router_utils/prompt_caching_cache.py tests/router_unit_tests/test_router_prompt_caching.py tests/test_litellm/test_prompt_caching_cache.py

Co-authored-by: OmX <omx@oh-my-codex.dev>
2026-05-21 17:32:02 +08:00

19 lines
625 B
Python

from litellm.router_utils.prompt_caching_cache import PromptCachingCache
def test_prompt_caching_affinity_ttl_respects_one_hour_cache_control():
messages = [
{
"role": "system",
"content": [
{
"type": "text",
"text": "Long-lived prompt cache prefix",
"cache_control": {"type": "ephemeral", "ttl": "1h"},
}
],
},
{"role": "user", "content": "This is outside the cacheable prefix"},
]
assert PromptCachingCache.get_prompt_caching_ttl_seconds(messages) == 3600