From c11477fb6fa5de8836bab63665662de054a09fbf Mon Sep 17 00:00:00 2001 From: yuneng-jiang Date: Sat, 7 Mar 2026 16:25:52 -0800 Subject: [PATCH] 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 --- .../ui_crud_endpoints/proxy_setting_endpoints.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/litellm/proxy/ui_crud_endpoints/proxy_setting_endpoints.py b/litellm/proxy/ui_crud_endpoints/proxy_setting_endpoints.py index 04b524ebbb7..076a2c3bffd 100644 --- a/litellm/proxy/ui_crud_endpoints/proxy_setting_endpoints.py +++ b/litellm/proxy/ui_crud_endpoints/proxy_setting_endpoints.py @@ -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 {