From afa21f9a0b101ba6030b2c9e3a81058fb477f8b0 Mon Sep 17 00:00:00 2001 From: PRABHU KIRAN VANDRANKI <72809214+VANDRANKI@users.noreply.github.com> Date: Fri, 17 Apr 2026 12:06:17 -0400 Subject: [PATCH] fix: move TTL global assignments after Cache() succeeds to avoid partial state on failure --- litellm/proxy/proxy_server.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index e1551ee7fec..1ad27934cc9 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -2796,14 +2796,16 @@ class ProxyConfig: global redis_usage_cache, llm_router from litellm import Cache + # Construct the cache first; only update global TTL defaults on success + # so that a failed initialisation does not leave partial global state. + litellm.cache = Cache(**cache_params) + if "default_in_memory_ttl" in cache_params: litellm.default_in_memory_ttl = cache_params["default_in_memory_ttl"] if "default_redis_ttl" in cache_params: litellm.default_redis_ttl = cache_params["default_redis_ttl"] - litellm.cache = Cache(**cache_params) - if litellm.cache is not None and isinstance( litellm.cache.cache, (RedisCache, RedisClusterCache) ):