Give the homepage a stated freshness - #73
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-Controlat 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.astrosetsCache-Control—public, max-age=60, s-maxage=60, stale-while-revalidate=300, using the same idiomArticleLayoutalready uses. An hour is right for an article, which is finished once it publishes, and wrong here.stale-while-revalidatekeeps the short TTL cheap: a spike is still served from cache while one request refreshes it.getHomepageArticlesdropsforce-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 ownCache-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-cachecall 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/homepagenow returns the 60s header.🤖 Generated with Claude Code