Skip to content

Give the homepage a stated freshness - #73

Merged
ssavutu merged 1 commit into
mainfrom
fix/homepage-cache-freshness
Aug 7, 2026
Merged

Give the homepage a stated freshness#73
ssavutu merged 1 commit into
mainfrom
fix/homepage-cache-freshness

Conversation

@ssavutu

@ssavutu ssavutu commented Aug 7, 2026

Copy link
Copy Markdown
Member

Why

Companion to triangle-cms#206, which adds a featured-article toggle so editors can pick the story that runs as the big centre card. That works without any change here — the CMS sorts server-side and news[0] is already the lead card — but it exposed that nothing in the chain says how long a copy of the homepage stays good.

The homepage is the editors' live control surface: the featured lead, the breaking banner and the carousel all change on demand. It was the one page sending no Cache-Control at all, so every intermediary applied its own heuristic and an editor swapping the lead had no bound on when readers would see it.

Changes

  • index.astro sets Cache-Controlpublic, max-age=60, s-maxage=60, stale-while-revalidate=300, using the same idiom ArticleLayout already uses. An hour is right for an article, which is finished once it publishes, and wrong here. stale-while-revalidate keeps the short TTL cheap: a spike is still served from cache while one request refreshes it.
  • getHomepageArticles drops force-cache — that mode means "reuse the stored response even when it is stale," which on the one endpoint carrying the featured lead and the breaking banner lets an editor's change sit invisible behind an entry with no expiry. 'default' honours the CMS's own Cache-Control (60s, added in the companion PR), so the response is still cached, just never past the bound the CMS states.

The other ~10 force-cache call sites are unchanged — only the homepage is time-critical.

Testing

astro check — 0 errors. The CMS side is verified in the companion PR, including a live check that /v1/homepage now returns the 60s header.

🤖 Generated with Claude Code

The homepage is the editors' live control surface -- the featured lead,
the breaking banner and the carousel all change on demand -- but it was
the one page that said nothing about how long a copy of it stays good.
Article pages have set Cache-Control since ArticleLayout; the homepage
sent none, so every cache in front of us applied its own heuristic and an
editor changing the lead had no bound on when readers would see it.

An hour is right for an article, which is finished once it publishes, and
wrong here: 60s, with stale-while-revalidate so a traffic spike is still
served from cache while one request refreshes it.

The homepage fetch also drops force-cache, which means "reuse the stored
response even when it is stale". On the one endpoint carrying the
featured lead and the breaking banner, that is the wrong default: it lets
an editor's change sit invisible behind an entry with no expiry. 'default'
honours the CMS's own Cache-Control, so the response is still cached --
just never past the bound the CMS states. The other call sites keep
force-cache; only the homepage is time-critical.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ssavutu
ssavutu merged commit 6fa3cf2 into main Aug 7, 2026
1 check passed
@ssavutu
ssavutu deleted the fix/homepage-cache-freshness branch August 7, 2026 05:16
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