From 0119c1efaa39acd216a06f5fb450042ebe5f9c8d Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Sat, 24 May 2025 18:11:35 -0700 Subject: [PATCH] fix(auth_checks.py): bump in-memory cache ttl for user objects to 60s --- litellm/constants.py | 3 +++ litellm/proxy/auth/auth_checks.py | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/litellm/constants.py b/litellm/constants.py index fba57a2bf9..50df19bb7f 100644 --- a/litellm/constants.py +++ b/litellm/constants.py @@ -714,3 +714,6 @@ SECRET_MANAGER_REFRESH_INTERVAL = int( ) LITELLM_SETTINGS_SAFE_DB_OVERRIDES = ["default_internal_user_params"] SPECIAL_LITELLM_AUTH_TOKEN = ["ui-token"] +DEFAULT_MANAGEMENT_OBJECT_IN_MEMORY_CACHE_TTL = int( + os.getenv("DEFAULT_MANAGEMENT_OBJECT_IN_MEMORY_CACHE_TTL", 60) +) diff --git a/litellm/proxy/auth/auth_checks.py b/litellm/proxy/auth/auth_checks.py index 05a47dd359..8653e40c7a 100644 --- a/litellm/proxy/auth/auth_checks.py +++ b/litellm/proxy/auth/auth_checks.py @@ -20,7 +20,11 @@ import litellm from litellm._logging import verbose_proxy_logger from litellm.caching.caching import DualCache from litellm.caching.dual_cache import LimitedSizeOrderedDict -from litellm.constants import DEFAULT_IN_MEMORY_TTL, DEFAULT_MAX_RECURSE_DEPTH +from litellm.constants import ( + DEFAULT_IN_MEMORY_TTL, + DEFAULT_MANAGEMENT_OBJECT_IN_MEMORY_CACHE_TTL, + DEFAULT_MAX_RECURSE_DEPTH, +) from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider from litellm.proxy._types import ( RBAC_ROLES, @@ -727,7 +731,9 @@ async def get_user_object( # save the user object to cache await user_api_key_cache.async_set_cache( - key=user_id, value=response_dict, ttl=DEFAULT_IN_MEMORY_TTL + key=user_id, + value=response_dict, + ttl=DEFAULT_MANAGEMENT_OBJECT_IN_MEMORY_CACHE_TTL, ) # save to db access time