fetch: respect HTTP Cache-Control headers with TTL-based invalidation (#91729)#93228
Merged
lukesandberg merged 6 commits intoMay 14, 2026
Merged
Conversation
Contributor
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
6ed8c8c to
0d4133c
Compare
84cc1af to
e5ee47b
Compare
4d4ba2e to
8dfbea9
Compare
e5ee47b to
09e7e0e
Compare
| #[turbo_tasks::function(operation)] | ||
| async fn fetch_body(url: RcStr) -> Result<Vc<RcStr>> { | ||
| let client_vc = FetchClientConfig { | ||
| min_cache_control_secs: 0, |
Contributor
Contributor
Stats from current PR✅ No significant changes detected📊 All Metrics📖 Metrics GlossaryDev Server Metrics:
Build Metrics:
Change Thresholds:
⚡ Dev Server
📦 Dev Server (Webpack) (Legacy)📦 Dev Server (Webpack)
⚡ Production Builds
📦 Production Builds (Webpack) (Legacy)📦 Production Builds (Webpack)
📦 Bundle SizesBundle Sizes⚡ TurbopackClient Main Bundles
Server Middleware
Build DetailsBuild Manifests
📦 WebpackClient Main Bundles
Polyfills
Pages
Server Edge SSR
Middleware
Build DetailsBuild Manifests
Build Cache
🔄 Shared (bundler-independent)Runtimes
📎 Tarball URLCommit: 5357124 |
Contributor
Tests PassedCommit: 5357124 |
8dfbea9 to
af1f451
Compare
09e7e0e to
11516ac
Compare
11516ac to
f609aa2
Compare
af1f451 to
c326a28
Compare
90a5e99 to
588fe96
Compare
c326a28 to
13be82f
Compare
588fe96 to
df11034
Compare
bgw
approved these changes
May 13, 2026
fewer braces
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.

Summary
This is a re-application of the HTTP fetch part of #91729. Stacked on #93227.
Fix fetch to respect HTTP
Cache-ControlheadersPreviously,
fetchresults were cached indefinitely, meaning results would never be refreshed (unless the cache was invalidated). Now they aresession_dependentwith a TTL to ensure we respect HTTP cache settings (e.g. Google Fonts withmax-age=86400).New two-task pattern:
fetch_inner(NOTsession_dependent): Performs the HTTP request, grabs anInvalidatorfor itself, and returns the response + invalidator + absolute deadline. Cached across sessions.fetch(network,session_dependent): Reads the cachedfetch_innerresult and spawns a timer to invalidate when the TTL expires.On warm cache restore,
fetchre-executes (session-dependent), reads the persisted deadline fromfetch_inner's cached result, computes remaining TTL, and spawns a timer — no HTTP request unless the TTL has already expired. Mid-session, the timer fires and triggers a re-fetch.Error handling: On fetch failure,
fetch_innertakes a dependency onCompletion::session_dependent()so transient errors (network down, DNS failure) are retried on the next session without busy-looping.Test Plan
3 new integration tests in
turbo-tasks-fetch/tests/fetch.rs:ttl_invalidates_within_session— mock server returnsmax-age=1, body changes, verifies re-fetch after TTLttl_invalidates_on_session_restore— fetches with TTL, stops TT, waits for expiry, warm restores with new TT, verifies re-fetcherrors_retried_on_session_restore— server returns 500, stops TT, fixes server, warm restores, verifies success