fix(caching): inject default_in_memory_ttl in DualCache async_set_cache and async_set_cache_pipeline - #22241
Merged
1 commit merged intoMar 3, 2026
Conversation
…he and async_set_cache_pipeline DualCache.async_set_cache and async_set_cache_pipeline were missing the default_in_memory_ttl injection that the sync set_cache method has. This caused InMemoryCache to fall back to its own default_ttl (600s) instead of using DualCache's configured default_in_memory_ttl (typically 60s). This is particularly impactful for end-user budget enforcement in the proxy, where cached spend values could remain stale for 10 minutes instead of 1 minute, allowing users to exceed their budgets.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Greptile SummaryThis PR fixes a parity bug between the sync and async cache write paths in
Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| litellm/caching/dual_cache.py | Adds default_in_memory_ttl injection guard to async_set_cache and async_set_cache_pipeline, matching the existing sync set_cache pattern. Changes are minimal (4 lines total) and correctly replicate the existing logic. |
| tests/test_litellm/caching/test_dual_cache.py | Adds 4 well-structured unit tests covering the TTL injection fix. Tests use real InMemoryCache objects (no network calls) and verify both the default injection and explicit TTL override behaviors, as well as sync/async parity. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["DualCache.async_set_cache / async_set_cache_pipeline called"] --> B{"'ttl' in kwargs?"}
B -- Yes --> D["Use explicit TTL"]
B -- No --> C{"default_in_memory_ttl set?"}
C -- Yes --> E["Inject kwargs['ttl'] = default_in_memory_ttl"]
C -- No --> F["No TTL injected — InMemoryCache uses its own default_ttl"]
E --> G["InMemoryCache.async_set_cache with injected TTL"]
D --> G
F --> G
G --> H{"redis_cache present and not local_only?"}
H -- Yes --> I["RedisCache.async_set_cache with same kwargs"]
H -- No --> J["Done"]
I --> J
Last reviewed commit: 9766b52
ghost
merged commit Mar 3, 2026
239f044
into
BerriAI:litellm_oss_staging_03_02_2026
28 of 30 checks passed
2 tasks
fzowl
pushed a commit
to fzowl/litellm
that referenced
this pull request
Jun 24, 2026
…he and async_set_cache_pipeline (BerriAI#22241) DualCache.async_set_cache and async_set_cache_pipeline were missing the default_in_memory_ttl injection that the sync set_cache method has. This caused InMemoryCache to fall back to its own default_ttl (600s) instead of using DualCache's configured default_in_memory_ttl (typically 60s). This is particularly impactful for end-user budget enforcement in the proxy, where cached spend values could remain stale for 10 minutes instead of 1 minute, allowing users to exceed their budgets.
This pull request was closed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DualCache.async_set_cache and async_set_cache_pipeline were missing the default_in_memory_ttl injection that the sync set_cache method has. This caused InMemoryCache to fall back to its own default_ttl (600s) instead of using DualCache's configured default_in_memory_ttl (typically 60s).
This is particularly impactful for end-user budget enforcement in the proxy, where cached spend values could remain stale for 10 minutes instead of 1 minute, allowing users to exceed their budgets.
Relevant issues
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/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 reviewCI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Type
🐛 Bug Fix
Changes
provided and self.default_in_memory_ttl is set, the TTL is now forwarded to the underlying InMemoryCache call in both async paths.
Test