Skip to content

Refresh the server cache instead of only pre-warming it at startup #6

Description

@yav02

create_app() in src/mk_tracking/ui_app/app.py warms the cache exactly once, in the lifespan handler:

try:
    repo.list_issues()
    repo.list_mks()
    repo.preload_summaries()
except Exception as error:
    print(f"Cache pre-warm warning: {error}")

Two consequences follow.

Data is as old as the process. Once the app is running, nothing ever refreshes it. A long-lived process serves whatever the dataset looked like at boot. On a site that makes claims about what elected officials said, silently serving stale positions is worse than being briefly unavailable.

A failed pre-warm degrades quietly. The except prints a warning and carries on, so the app starts with a cold cache and every subsequent request runs the full BigQuery query synchronously.

What to build

  • A TTL or periodic background refresh, so cached data has a bounded age.
  • A way to see cache age — a field on the health endpoint is enough.
  • Retry or fail-fast on startup rather than proceeding cold, so a broken pre-warm is visible instead of turning into a slow site.

This becomes more pressing once the pipeline runs on a schedule rather than by hand — see the self-hosting issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions