Limit Fastly cache TTL for error responses (status >= 400) to 30s#23616
Merged
benhalpern merged 3 commits intoJul 15, 2026
Conversation
Contributor
|
Thank you for opening this PR! We appreciate you! For all pull requests coming from third-party forks we will need to A Forem Team member will review this contribution and get back to |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates Forem’s Fastly VCL to ensure HTTP error responses (status >= 400) are only cached for a short duration (30 seconds), preventing long-lived cached 404s/other errors (e.g., after publishing or correcting a custom domain configuration).
Changes:
- Add a
beresp.status >= 400condition in thestale_while_revalidate_controls.vclsnippet. - Set
beresp.ttl = 30sfor error responses and explicitly mark them cacheable.
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.
Goal
Limit the Fastly cache TTL for error status responses (HTTP status >= 400) to 30 seconds.
Problem Context
When a request to a custom domain (or standard page) fails or is misconfigured, Fastly caches the resulting 404 response page (or fallback redirects) using its default service TTL (which is configured for up to 30 days) when the response lacks explicit Cache-Control/Surrogate-Control headers. This causes pages (like newly-published articles) to render as 404 to users for an extended period, even after they have been published or the domain configuration is corrected.
Proposed Changes
This PR modifies the block in the Fastly VCL snippet
stale_while_revalidate_controls.vclto:beresp.status >= 400).beresp.ttl = 30s(caching them for at most 30 seconds to absorb traffic spikes without keeping errors stuck indefinitely).beresp.cacheable = trueso the error responses are explicitly cacheable for that duration.Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.