Repository navigation
Stream the page on a cache miss in the built-in memory cache provider #1458
guryanov-a
started this conversation in
Proposal
Replies: 2 comments 1 reply
|
Sounds like a good idea. I think we’d accept a PR for this — no need to go through the RFC process. |
0 replies
|
The pull request is ready for review: withastro/astro#18591 Its CI is currently blocked by withastro/astro#18598: the |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Summary
On a cache miss, the built-in memory cache provider (
astro/cache/memory) should stream the rendered page to the visitor while it stores a copy, instead of reading the whole page into memory before sending the first byte.Background & Motivation
A cache miss is a request for a page that is not in the cache yet: every page after a purge, and every page that has not been requested since the server started. On a miss, the provider clones the response, waits until the clone's whole body has been read with
arrayBuffer(), stores it, and only then returns the original to the visitor (memory-provider.ts#L540-L553, with the read inserializeResponseat L361). Seen on Astro 7.3.8; the same code is onmaintoday.Astro renders pages as a stream, so the browser can start loading the head, CSS and the top of the page while the rest is still rendering. Waiting for the full body removes that on every miss: the time to first byte (how long the visitor waits before any of the page arrives) becomes the time of the slowest part of the render. Cached hits are unaffected, so the cost lands on exactly the requests that are already the slowest.
Goals
Varykey, tags).Example
No API change. Inside the provider, the miss path could return the visitor's copy at once and store the cache copy when its read finishes, for example:
(
storeKey(entry)stands for the existingVary-based key logic.)Alternative solutions
Current workarounds
astro/cache/memorywith a custom provider that streams on a miss and stores a copy when the stream ends. This means re-implementing the LRU, theVarykeying and the tag and path invalidation that the built-in provider already has.All reactions