From 939467b351ef226d7f1dd32465c3ae86261368cc Mon Sep 17 00:00:00 2001 From: Lavya Tandel Date: Mon, 10 Aug 2026 23:34:38 +0530 Subject: [PATCH 1/2] fix(router): apply cache_kwargs regardless of Redis presence (#36309) --- litellm/router.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/litellm/router.py b/litellm/router.py index 0b9f12c8da3..b91c2e364e3 100644 --- a/litellm/router.py +++ b/litellm/router.py @@ -971,11 +971,16 @@ class Router: ### CACHING ### cache_type: Literal["local", "redis", "redis-semantic", "s3", "disk"] = "local" # default to an in-memory cache redis_cache = None - cache_config: Final[dict[str, Any]] = {} + cache_config: dict[str, Any] = {} # mutable-ok: built incrementally from cache_kwargs, then passed to litellm.Cache() + + # Apply cache_kwargs so they're available regardless of Redis presence. + # "type" is extracted to avoid duplicate keyword arg in litellm.Cache() below. + cache_config.update(cache_kwargs) + cache_type = cache_config.pop("type", cache_type) # rebind-ok: cache_type may be overridden to "redis" below self.client_ttl = client_ttl if redis_url is not None or (redis_host is not None and redis_port is not None): - cache_type = "redis" + cache_type = "redis" # rebind-ok: switch to Redis when Redis params are provided if redis_url is not None: cache_config["url"] = redis_url @@ -995,8 +1000,6 @@ class Router: ) cache_config["db"] = str(redis_db) - # Add additional key-value pairs from cache_kwargs - cache_config.update(cache_kwargs) redis_cache = self._create_redis_cache(cache_config) if cache_responses: From ef4f1bdba14a759cc632b4440c9faf2cb2bb535d Mon Sep 17 00:00:00 2001 From: Lavya Tandel Date: Tue, 11 Aug 2026 22:53:38 +0530 Subject: [PATCH 2/2] style(router): remove explanatory comments per review feedback --- litellm/router.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/litellm/router.py b/litellm/router.py index b91c2e364e3..8ab38305b7c 100644 --- a/litellm/router.py +++ b/litellm/router.py @@ -969,18 +969,16 @@ class Router: self.deployment_names: list = [] # names of models under litellm_params. ex. azure/chatgpt-v-2 self.deployment_latency_map = {} ### CACHING ### - cache_type: Literal["local", "redis", "redis-semantic", "s3", "disk"] = "local" # default to an in-memory cache + cache_type: Literal["local", "redis", "redis-semantic", "s3", "disk"] = "local" redis_cache = None - cache_config: dict[str, Any] = {} # mutable-ok: built incrementally from cache_kwargs, then passed to litellm.Cache() + cache_config: dict[str, Any] = {} - # Apply cache_kwargs so they're available regardless of Redis presence. - # "type" is extracted to avoid duplicate keyword arg in litellm.Cache() below. cache_config.update(cache_kwargs) - cache_type = cache_config.pop("type", cache_type) # rebind-ok: cache_type may be overridden to "redis" below + cache_type = cache_config.pop("type", cache_type) self.client_ttl = client_ttl if redis_url is not None or (redis_host is not None and redis_port is not None): - cache_type = "redis" # rebind-ok: switch to Redis when Redis params are provided + cache_type = "redis" if redis_url is not None: cache_config["url"] = redis_url