mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-14 09:03:16 +00:00
revert: drop the LTS-only sync cache read changes
This revertsdfc92ba4cd,d94be668d2andc2ba33609a. Async speech now awaits the bridge, so the proxy reads the cache through the async path, which already honors s-maxage 0 and reads s-max-age first. The sync read goes back to the line's code, which matches main
This commit is contained in:
parent
4ca7a2597c
commit
b706bf16f8
3 changed files with 1 additions and 51 deletions
|
|
@ -662,9 +662,7 @@ class Cache:
|
|||
cache_key = self.get_cache_key(**kwargs)
|
||||
if cache_key is not None:
|
||||
cache_control_args: Final[DynamicCacheControl] = kwargs.get("cache", {})
|
||||
max_age: Final = cache_control_args.get(
|
||||
"s-max-age", cache_control_args.get("s-maxage", float("inf"))
|
||||
)
|
||||
max_age = cache_control_args.get("s-maxage") or cache_control_args.get("s-max-age") or float("inf")
|
||||
cache_lookup_kwargs: Final = self._get_safe_cache_lookup_kwargs(kwargs)
|
||||
if dynamic_cache_object is not None:
|
||||
cached_result = dynamic_cache_object.get_cache(cache_key, **cache_lookup_kwargs)
|
||||
|
|
|
|||
|
|
@ -1437,53 +1437,6 @@ async def test_caching_with_cache_controls(monkeypatch: pytest.MonkeyPatch) -> N
|
|||
assert async_ttl_first.id == async_ttl_second.id
|
||||
|
||||
|
||||
@pytest.mark.parametrize("max_age_key", ["s-maxage", "s-max-age"])
|
||||
def test_sync_completion_with_zero_s_maxage_skips_the_cached_response(
|
||||
monkeypatch: pytest.MonkeyPatch, max_age_key: str
|
||||
) -> None:
|
||||
monkeypatch.setattr(litellm, "cache", Cache(type=LiteLLMCacheType.LOCAL))
|
||||
messages: Final = [{"role": "user", "content": f"zero s-maxage {uuid.uuid4().hex}"}]
|
||||
first: Final = completion(model="gpt-4o-mini", messages=messages, mock_response="first")
|
||||
zero_max_age: Final = completion(
|
||||
model="gpt-4o-mini", messages=messages, cache={max_age_key: 0}, mock_response="second"
|
||||
)
|
||||
open_max_age: Final = completion(
|
||||
model="gpt-4o-mini", messages=messages, cache={max_age_key: 60}, mock_response="third"
|
||||
)
|
||||
|
||||
assert zero_max_age.id != first.id
|
||||
assert open_max_age.id == zero_max_age.id
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
("cache_controls", "serves_cached"),
|
||||
[
|
||||
({"s-maxage": 0, "s-max-age": 60}, True),
|
||||
({"s-maxage": 60, "s-max-age": 0}, False),
|
||||
({"s-maxage": None, "s-max-age": 0}, False),
|
||||
],
|
||||
)
|
||||
async def test_sync_and_async_completion_follow_s_max_age_when_both_max_age_keys_are_sent(
|
||||
monkeypatch: pytest.MonkeyPatch, cache_controls: dict[str, int | None], serves_cached: bool
|
||||
) -> None:
|
||||
monkeypatch.setattr(litellm, "cache", Cache(type=LiteLLMCacheType.LOCAL))
|
||||
sync_messages: Final = [{"role": "user", "content": f"sync both max-age keys {uuid.uuid4().hex}"}]
|
||||
sync_first: Final = completion(model="gpt-4o-mini", messages=sync_messages, mock_response="first")
|
||||
sync_second: Final = completion(
|
||||
model="gpt-4o-mini", messages=sync_messages, cache=cache_controls, mock_response="second"
|
||||
)
|
||||
async_messages: Final = [{"role": "user", "content": f"async both max-age keys {uuid.uuid4().hex}"}]
|
||||
async_first: Final = await acompletion(model="gpt-4o-mini", messages=async_messages, mock_response="first")
|
||||
await asyncio.gather(*_PENDING_CACHE_WRITES)
|
||||
async_second: Final = await acompletion(
|
||||
model="gpt-4o-mini", messages=async_messages, cache=cache_controls, mock_response="second"
|
||||
)
|
||||
|
||||
assert (sync_second.id == sync_first.id) is serves_cached
|
||||
assert (async_second.id == async_first.id) is serves_cached
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_embedding_caching_redis_ttl(monkeypatch: pytest.MonkeyPatch, redis_client_without_network: None) -> None:
|
||||
mock_pipeline: Final = AsyncMock()
|
||||
|
|
|
|||
|
|
@ -5013,7 +5013,6 @@ async def test_speech_gemini_tts_behind_the_router_waits_as_long_as_the_same_cha
|
|||
[
|
||||
({}, {}, 1),
|
||||
({}, {"cache": {"no-cache": True}}, 2),
|
||||
({}, {"cache": {"s-maxage": 0}}, 2),
|
||||
({"cache": {"no-store": True}}, {}, 2),
|
||||
({}, {"caching": False}, 2),
|
||||
({}, {"caching": "yes"}, 2),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue