Skip to content

Commit

Permalink
feat: added possibility to toggle background cache system (#202)
Browse files Browse the repository at this point in the history
* feat: added possibility to toggle background cache system

* bump version
  • Loading branch information
TeKrop authored Oct 15, 2024
1 parent aa615ce commit 7c6b6a3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/commands/check_and_update_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "overfast-api"
version = "2.37.2"
version = "2.38.0"
description = "Overwatch API giving data about heroes, maps, and players statistics."
license = {file = "LICENSE"}
authors = [
Expand Down
9 changes: 9 additions & 0 deletions tests/commands/test_check_and_update_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7c6b6a3

Please sign in to comment.