Hi all.
I’ve used this guide to try and put together a quick proof-of-concept for a stale-while-revalidate cache strategy, leveraging Netlify’s great ISR/cache model.
I have a demo site here (SSR with the Netlify adapter): https://astro-relume-netlify.in-beta.link/.
In the front-matter of the index route, I have:
Astro.response.headers.set(
"Cache-Control",
"public, max-age=0, must-revalidate"
);
Astro.response.headers.set(
"Netlify-CDN-Cache-Control",
"public, durable, s-maxage=300, stale-while-revalidate=604800"
);
What I expect to happen is that the first visitor after a deploy would get a miss and then subsequent visit with the would receive a hit or a stale copy.
What I see is that every new visitor gets an edge miss and a durable bypass, with the response headers looking like this:
cache-control: public,max-age=0,must-revalidate
cache-status: "Netlify Durable"; fwd=bypass
cache-status: "Netlify Edge"; fwd=miss
The page doesn’t use any cookies or query strings etc. and to rule anything specific to that page out, I’ve added a test route of Cache Test which only contains the following in a single index.astro file:
---
Astro.response.headers.set(
"Cache-Control",
"public, max-age=0, must-revalidate"
);
Astro.response.headers.set(
"Netlify-CDN-Cache-Control",
"public, durable, s-maxage=300, stale-while-revalidate=604800"
);
---
<html>
<head><title>Cache Test</title></head>
<body>
<h1>Cache Test Page</h1>
<p>Testing Netlify caching: {new Date().toISOString()}</p>
</body>
</html>
But the response headers come back the same and you can see a fresh time stamp with each refresh.
Any ideas what I’m doing wrong here?