From e6a325ac8fd66e4542df7421c0c339816deab38a Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Wed, 10 Dec 2025 07:59:54 -0600 Subject: [PATCH] Add CACHE_ENABLED env var to toggle Redis caching (v2.2.1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Set CACHE_ENABLED=false to disable caching without stopping Redis - Defaults to true (caching enabled) - Useful for draft periods requiring real-time data 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- VERSION | 2 +- app/dependencies.py | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/VERSION b/VERSION index ccbccc3..c043eea 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.2.0 +2.2.1 diff --git a/app/dependencies.py b/app/dependencies.py index 9480559..b95747d 100644 --- a/app/dependencies.py +++ b/app/dependencies.py @@ -26,23 +26,28 @@ logger = logging.getLogger('discord_app') REDIS_HOST = os.environ.get('REDIS_HOST', 'localhost') REDIS_PORT = int(os.environ.get('REDIS_PORT', '6379')) REDIS_DB = int(os.environ.get('REDIS_DB', '0')) +CACHE_ENABLED = os.environ.get('CACHE_ENABLED', 'true').lower() == 'true' # Initialize Redis client with connection error handling -try: - redis_client = Redis( - host=REDIS_HOST, - port=REDIS_PORT, - db=REDIS_DB, - decode_responses=True, - socket_connect_timeout=5, - socket_timeout=5 - ) - # Test connection - redis_client.ping() - logger.info(f"Redis connected successfully at {REDIS_HOST}:{REDIS_PORT}") -except Exception as e: - logger.warning(f"Redis connection failed: {e}. Caching will be disabled.") +if not CACHE_ENABLED: + logger.info("Caching disabled via CACHE_ENABLED=false") redis_client = None +else: + try: + redis_client = Redis( + host=REDIS_HOST, + port=REDIS_PORT, + db=REDIS_DB, + decode_responses=True, + socket_connect_timeout=5, + socket_timeout=5 + ) + # Test connection + redis_client.ping() + logger.info(f"Redis connected successfully at {REDIS_HOST}:{REDIS_PORT}") + except Exception as e: + logger.warning(f"Redis connection failed: {e}. Caching will be disabled.") + redis_client = None oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") priv_help = False if not os.environ.get('PRIVATE_IN_SCHEMA') else os.environ.get('PRIVATE_IN_SCHEMA').upper()