Skip to content

feat: durable cache so finished sessions survive restarts - #44

Merged
JustMaris merged 1 commit into
masterfrom
feat/durable-cache
Sep 24, 2026
Merged

JustMaris merged 1 commit into
masterfrom
feat/durable-cache

Conversation

@JustMaris

Copy link
Copy Markdown
Member

Summary

OpenF1's free tier returns 401 Live F1 session in progress for everything (past sessions included) for a stretch around every live session - observed starting ~15 min before a session and lifting ~30 min after. Finished sessions were already kept in memory so a lockout couldn't blank them, but a restart wiped that: a deploy landing inside a lockout left the Tyre Usage and Latest Session tiles empty until it lifted.

  • cache.getDurable / setDurable keep never-changing data in memory and, when CACHE_DIR is set, mirror it to disk as small JSON files (atomic temp-file + rename; ignored after 30 days). tyre_usage and latest_session use it for finished sessions; anything else immutable can too.
  • Image: /data owned by the non-root user (65532) and CACHE_DIR=/data by default. Mount a volume there to persist; without one it still works, it just doesn't outlive the container.
  • Startup probe: logs a warning if the directory isn't writable, instead of silently not persisting.
  • README + docker-compose example updated.

Test plan

  • gofmt / go vet / go test ./... clean; new test: a "restarted" instance (empty memory, same dir, upstream locked out) still serves tyre and latest-session data, while one without a dir shows upstream_error
  • Built the real scratch image and ran it: fresh named volume -> starts clean; no volume -> starts clean; read-only mount -> logs the "CACHE_DIR is not writable" warning
  • Not exercised against a real OpenF1 lockout end-to-end; check after deploy that a restart during a lockout keeps the tiles populated

Cluster side (PVC + mount): see the companion PR in drumandbytes/cluster.

OpenF1's free tier locks out all access (past sessions included) for a
stretch around every live session. Finished sessions were already kept
in memory so a lockout couldn't blank them, but a restart wiped that -
a deploy landing during a lockout left the tyre and latest-session
tiles empty until it lifted.

- cache: getDurable/setDurable keep never-changing data in memory and,
  when CACHE_DIR is set, mirror it to disk as small JSON files (atomic
  write, ignored after 30 days). tyre_usage and latest_session use it
  for finished sessions; anything else immutable can too.
- image: /data owned by the non-root user, CACHE_DIR=/data by default -
  mount a volume there to persist; without one it still works, it just
  doesn't outlive the container.
- startup probes the directory and logs a warning if it isn't writable,
  instead of silently not persisting.
- README, docker-compose example.

Verified in the real scratch image: fresh named volume and no volume
both start clean; a read-only mount logs the warning.
@JustMaris
JustMaris merged commit 1247a12 into master Sep 24, 2026
7 checks passed
@JustMaris
JustMaris deleted the feat/durable-cache branch September 24, 2026 11:57
@dnb-robot dnb-robot Bot mentioned this pull request Sep 24, 2026
JustMaris added a commit that referenced this pull request Sep 26, 2026
OpenF1's free tier locks out all access (past sessions included) for a
stretch around every live session. Finished sessions were already kept
in memory so a lockout couldn't blank them, but a restart wiped that -
a deploy landing during a lockout left the tyre and latest-session
tiles empty until it lifted.

- cache: getDurable/setDurable keep never-changing data in memory and,
  when CACHE_DIR is set, mirror it to disk as small JSON files (atomic
  write, ignored after 30 days). tyre_usage and latest_session use it
  for finished sessions; anything else immutable can too.
- image: /data owned by the non-root user, CACHE_DIR=/data by default -
  mount a volume there to persist; without one it still works, it just
  doesn't outlive the container.
- startup probes the directory and logs a warning if it isn't writable,
  instead of silently not persisting.
- README, docker-compose example.

Verified in the real scratch image: fresh named volume and no volume
both start clean; a read-only mount logs the warning.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant