mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-06 08:16:43 +00:00
fix: add 10-minute TTL to UI settings cache and refresh on GET
All async_set_cache calls for UI settings now use a 600s TTL so entries auto-expire in multi-instance deployments without Redis. The GET /ui_settings endpoint also refreshes the cache after reading from DB, ensuring the admin who just toggled the flag sees fresh values propagated to other code paths immediately. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
af61132a3f
commit
c11477fb6f
1 changed files with 11 additions and 3 deletions
|
|
@ -981,6 +981,7 @@ async def get_in_product_nudges():
|
|||
|
||||
|
||||
UI_SETTINGS_CACHE_KEY = "ui_settings:settings_dict"
|
||||
UI_SETTINGS_CACHE_TTL = 600 # 10 minutes
|
||||
|
||||
|
||||
async def get_ui_settings_cached() -> Dict[str, Any]:
|
||||
|
|
@ -1014,9 +1015,9 @@ async def get_ui_settings_cached() -> Dict[str, Any]:
|
|||
k: v for k, v in ui_settings.items() if k in ALLOWED_UI_SETTINGS_FIELDS
|
||||
}
|
||||
|
||||
# 3. Populate cache
|
||||
# 3. Populate cache with TTL
|
||||
await user_api_key_cache.async_set_cache(
|
||||
key=UI_SETTINGS_CACHE_KEY, value=ui_settings
|
||||
key=UI_SETTINGS_CACHE_KEY, value=ui_settings, ttl=UI_SETTINGS_CACHE_TTL
|
||||
)
|
||||
|
||||
return ui_settings
|
||||
|
|
@ -1066,6 +1067,13 @@ async def get_ui_settings():
|
|||
|
||||
general_settings.update(_flags_to_sync)
|
||||
|
||||
# Refresh DualCache so other code paths (e.g. /user/filter/ui) see fresh values
|
||||
from litellm.proxy.proxy_server import user_api_key_cache
|
||||
|
||||
await user_api_key_cache.async_set_cache(
|
||||
key=UI_SETTINGS_CACHE_KEY, value=ui_settings, ttl=UI_SETTINGS_CACHE_TTL
|
||||
)
|
||||
|
||||
# Build config-like object for schema helper
|
||||
config: Dict[str, Any] = {"litellm_settings": {"ui_settings": ui_settings}}
|
||||
|
||||
|
|
@ -1157,7 +1165,7 @@ async def update_ui_settings(
|
|||
k: v for k, v in ui_settings.items() if k in ALLOWED_UI_SETTINGS_FIELDS
|
||||
}
|
||||
await user_api_key_cache.async_set_cache(
|
||||
key=UI_SETTINGS_CACHE_KEY, value=sanitized
|
||||
key=UI_SETTINGS_CACHE_KEY, value=sanitized, ttl=UI_SETTINGS_CACHE_TTL
|
||||
)
|
||||
|
||||
return {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue