diff --git a/.env.dist b/.env.dist index b98c2444..b3898c89 100644 --- a/.env.dist +++ b/.env.dist @@ -15,6 +15,7 @@ REDIS_HOST=redis REDIS_PORT=6379 # Cache configuration +BACKGROUND_CACHE_REFRESH_ENABLED=true EXPIRED_CACHE_REFRESH_LIMIT=3600 HEROES_PATH_CACHE_TIMEOUT=86400 HERO_PATH_CACHE_TIMEOUT=86400 diff --git a/app/commands/check_and_update_cache.py b/app/commands/check_and_update_cache.py index 6e85a8e9..375e5e0d 100644 --- a/app/commands/check_and_update_cache.py +++ b/app/commands/check_and_update_cache.py @@ -102,6 +102,10 @@ async def retrieve_data(key: str, parser: AbstractParser): async def main(): """Main coroutine of the script""" + if not settings.background_cache_refresh_enabled: + logger.warning("Background Cache Refresh system is disabled") + raise SystemExit + logger.info("Starting Redis cache update...") keys_to_update = get_soon_expired_cache_keys() diff --git a/app/config.py b/app/config.py index 946ba332..3967715d 100644 --- a/app/config.py +++ b/app/config.py @@ -68,6 +68,9 @@ class Settings(BaseSettings): # CACHE CONFIGURATION ############ + # Enable background cache refresh system (check_and_update_cache) + background_cache_refresh_enabled: bool = True + # Prefix for keys in API Cache with entire payload (Redis). # Used by nginx as main API cache. api_cache_key_prefix: str = "api-cache" diff --git a/tests/commands/test_check_and_update_cache.py b/tests/commands/test_check_and_update_cache.py index 4751e746..292363bb 100644 --- a/tests/commands/test_check_and_update_cache.py +++ b/tests/commands/test_check_and_update_cache.py @@ -32,6 +32,15 @@ def _set_no_spread_percentage(): yield +@pytest.fixture(autouse=True) +def _set_background_cache_refresh_enabled(): + with patch( + "app.common.cache_manager.settings.background_cache_refresh_enabled", + True, + ): + yield + + def test_check_and_update_gamemodes_cache_to_update( cache_manager: CacheManager, locale: str,