INNER CODE UNIT · Python

_get_latest_github_version

Duelion/homebox-companion · server/app.py:78

async def _get_latest_github_version() -> str | None:
    """Fetch the latest release version from GitHub with caching and proper error handling.

    Implements both positive caching (1 hour for successful checks) and negative caching
    (5 minutes for failed checks) to prevent hammering the GitHub API during outages.

    Uses double-checked locking to minimize lock hold time: first checks cache without
    lock, then acquires lock only when refresh is needed and re-checks to avoid
    thundering herd.
    """
    now = time.time()

    # Quick cache check without lock (cache reads are safe)
    last_check = _version_cache["last_check"]
    if isinstance(last_check, (int, float)) and last_check > 0:
        # If we have a cached version, use positive TTL
        if _version_cache["latest_version"] is not None:
            if now - last_check < VERSION_CACHE_TTL:

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…