Skip to content

fix: set Cache-Control from streak freshness (#944) - #955

Open
webywz wants to merge 1 commit into
DenverCoder1:mainfrom
webywz:fix/cache-control-944
Open

webywz wants to merge 1 commit into
DenverCoder1:mainfrom
webywz:fix/cache-control-944

Conversation

@webywz

@webywz webywz commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #944.

index.php previously sent Cache-Control: public, max-age=86400 before stats were generated. GitHub Camo honors that header, so a card generated on day N could stay cached until the same wall-clock time on day N+1 — even though statsMissingOrStale() would already treat it as stale after local midnight.

This PR chooses the HTTP lifetime after stats (or an error) are known:

Response max-age
Fresh streak (includes today / current week) Seconds until next midnight in the request timezone, capped at 24h
Stale by statsMissingOrStale(), missing stats, or error cards 1 hour (SHORT_CACHE_DURATION)

File-cache behavior (CACHE_DURATION, statsMissingOrStale) is unchanged.

Test plan

  • Added tests/HttpCacheTest.php covering null/zero/stale → 1h and fresh → until midnight (capped)
  • composer test (HttpCacheTest + existing suite)
  • Manual: hit a card URL and confirm cache-control is max-age=<seconds until midnight> when the streak includes today, and ~3600 on an error / nonexistent user

Notes

Issue author noted streak-length-0 already skips the file cache every request; a short HTTP lifetime there means more origin hits (and GitHub API calls). This follows the issue’s proposed solution (short lifetime when statsMissingOrStale() is true). Happy to adjust that trade-off if maintainers prefer a longer header for the zero-streak case.

HTTP max-age was always 86400 before stats were generated, so Camo could
keep a card past midnight even after the server treated it as stale.

Choose max-age after stats are known: until next midnight (capped at 24h)
when the streak includes today; SHORT_CACHE_DURATION (1h) for stale or
error responses. Adds unit tests for the lifetime helper.

This branch has not been deployed

No deployments
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.

README card can lag a day behind: HTTP cache lifetime is always 24 hours

1 participant