litellm/tests/unit/caching
ryan-crabbe-berri cae28c5515
perf(caching): hash response cache keys piece by piece and store under the looked-up key (#52267)
* test(caching): pin response cache keys and cover large image and clamped max_tokens requests

Pins the cache key to the sha256 of the same formatted request text it has always
used, caps memory while hashing a request full of large images, and checks that a
repeat of a request whose max_tokens LiteLLM lowered is served from the cache on
async, sync and no-cache paths and through the proxy.

* perf(caching): hash cache keys piece by piece and reuse the lookup key on every write

Requests carrying large base64 images no longer build the whole request as one
string to hash it. Only the parts holding a large string are walked, so small
requests stay at C speed, and the hashed bytes are unchanged so existing cache
entries and the Rust cache reader keep hitting.

The key is computed once before max_tokens is clamped (async, sync, and when the
read is skipped via no-cache), and every cache write reuses it, so a clamped
request is stored under the key its identical repeat looks up.

* fix(caching): drop a comment that restated the cache check and measure only the key's own memory in the test

* test(code-quality): allow the depth-capped cache key walkers in the recursion detector
2026-11-17 15:58:07 -08:00
..
__init__.py
_event_loop_reuse.py fix(caching): key cached async clients by a per-loop token instead of id(loop) (#48877) 2026-10-29 13:14:48 -07:00
redis_batch_double.py refactor(redis): delete the Python RedisBatch now that every request op is native (#51383) 2026-11-13 03:22:28 +00:00
test_azure_blob_cache.py
test_cache_preset_key.py
test_caching.py perf(caching): hash response cache keys piece by piece and store under the looked-up key (#52267) 2026-11-17 15:58:07 -08:00
test_caching_handler.py perf(caching): hash response cache keys piece by piece and store under the looked-up key (#52267) 2026-11-17 15:58:07 -08:00
test_check_and_fix_namespace_none_guard.py
test_dual_cache.py perf(caching): format dual cache debug logs lazily (#51902) 2026-11-15 06:50:04 +00:00
test_embedding_router.py refactor(router): move router callers onto the entry points and invert the proxy imports (#48847) 2026-10-29 17:26:33 +00:00
test_evicted_client_closer.py ci(unit): cut unit check time with cheaper per-test resets and fewer non-unit tests (#51864) 2026-11-14 15:41:30 -08:00
test_gcs_cache.py
test_in_memory_cache.py feat(router): add deployment rpd and tpd daily limits to enforce_model_rate_limits (#48875) 2026-10-28 15:52:44 -07:00
test_llm_caching_handler.py refactor(rust_bridge): route every Rust-to-Python call through host modules (#50822) 2026-11-11 01:57:54 +00:00
test_llm_client_cache_e2e.py
test_qdrant_semantic_cache.py perf(token_counter): memoize token counts of long texts per tokenizer (#51904) 2026-11-16 19:21:55 +00:00
test_redis_batch.py refactor(redis): delete the Python RedisBatch now that every request op is native (#51383) 2026-11-13 03:22:28 +00:00
test_redis_cache.py refactor(redis): delete the Python RedisBatch now that every request op is native (#51383) 2026-11-13 03:22:28 +00:00
test_redis_cluster_cache.py refactor(router): delete the python router core, the rust core is the only core (#50178) 2026-11-05 10:40:46 -08:00
test_redis_cluster_node_isolation.py
test_redis_connection_pool.py
test_redis_semantic_cache.py perf(token_counter): memoize token counts of long texts per tokenizer (#51904) 2026-11-16 19:21:55 +00:00
test_request_redis_batch_post_call.py feat(callbacks-parallel-request-limiter): port parallel request limiter v3 to a rust callback (#51537) 2026-11-16 22:56:38 -08:00
test_request_redis_batch_pre_call.py feat(callbacks-parallel-request-limiter): port parallel request limiter v3 to a rust callback (#51537) 2026-11-16 22:56:38 -08:00
test_responses_stream_cache_keys.py
test_s3_cache.py
test_unit_test_caching.py fix(caching): read the cache key's model group from the router's metadata for the call (#48917) 2026-10-29 05:35:23 -07:00
test_valkey_semantic_cache.py ci(unit): cut unit check time with cheaper per-test resets and fewer non-unit tests (#51864) 2026-11-14 15:41:30 -08:00