[Fix] Cache LiteLLM_Config param reads in DualCache and batch - #26469
Conversation
|
Michael Riad Zaky seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Caching layer for LiteLLM_Config database readsThis PR introduces a DualCache (in-memory + optional Redis) to reduce repetitive per-param database queries for internal configuration values. All cache keys are derived from hardcoded param names, invalidation is called after every write path, and the affected endpoints remain behind admin-only auth. No new user-controlled inputs flow into cache keys or values, and no security boundaries are modified. Status: 0 open |
Greptile SummaryThis PR reduces DB read pressure in multi-pod deployments by introducing a Confidence Score: 5/5Safe to merge; only P2 style issues found, core caching and invalidation logic is sound. No P0 or P1 issues found. Previously flagged decorator-placement P1 is resolved in this version. Two P2 observations: return-type inconsistency and DEBUG-level logging for prefetch failures. litellm/proxy/utils.py — review the get_config_param return type contract
|
| Filename | Overview |
|---|---|
| litellm/proxy/utils.py | Adds module-level DualCache, get_config_param, prefetch_config_params, and invalidate_config_param; two P2 issues found. |
| litellm/proxy/proxy_server.py | Wires Redis layer, replaces direct Prisma calls with get_config_param, adds prefetch warm-up and invalidation after writes. |
| tests/test_litellm/proxy/test_proxy_server.py | Adds autouse cache-flush fixture and adapts mocks to new get_generic_data code path; test intent preserved. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[load_router_config] --> B[prefetch_config_params find_many batch query]
B --> C[litellm_config_cache DualCache in-memory + Redis TTL=60s]
D[get_config_param] --> E{Cache hit?}
E -- yes --> F[_unpack_config_row returns _ConfigRow shim]
E -- no --> G[get_generic_data Prisma find_first]
G --> H[store in cache]
H --> I[return real Prisma row]
J[Config write endpoint] --> K[invalidate_config_param async_delete_cache]
K --> C
L[PrismaClient.insert_data config table] --> K
Reviews (10): Last reviewed commit: "cache LiteLLM_Config param reads in Dual..." | Re-trigger Greptile
| if prisma_client is not None and hasattr( | ||
| prisma_client, "_config_param_cache" | ||
| ): | ||
| prisma_client._config_param_cache.redis_cache = redis_usage_cache |
There was a problem hiding this comment.
Redis attachment is skipped if
litellm.cache initialises before prisma_client
prisma_client._config_param_cache.redis_cache is only wired up here, inside the if litellm.cache is not None and isinstance(litellm.cache.cache, (RedisCache, RedisClusterCache)) block. In deployments where the cache is configured after this code path runs (or where prisma_client is initialised after load_router_config completes), the Redis layer will never be attached and all cross-pod cache sharing silently degrades to in-memory-only. Consider making the attachment explicit during PrismaClient.__init__ or adding a warning log when redis_cache remains None after startup.
…tinue docs - BerriAI/litellm#26469 needs-discussion (config DualCache + batched prefetch, WIP) - anomalyco/opencode#24262 request-changes (NIM deepseek-v4 chat_template_kwargs body-mutating fetch) - continuedev/continue#12216 merge-as-is (openrouter identification headers docs)
263e20f to
aaf08c3
Compare
aaf08c3 to
e1f269e
Compare
e1f269e to
48257eb
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
b530591 to
4a07db4
Compare
c867b73 to
e3ebf1f
Compare
e3ebf1f to
6052ce1
Compare
…duction [Fix] Cache LiteLLM_Config param reads in DualCache and batch
Relevant issues
Caches config parameter reads in dual cache and batches reads to reduce reading in multi-pod setups.
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/test_litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewScreenshots / Proof of Fix
Ran end to end on docker and confirmed lower read count through writing / reading, 2.8 queries per second down to 0.7 queries per second. The improvement is larger across higher pod counts.
Type
🐛 Bug Fix
✅ Test
Changes
proxy_server.py and utils.py