Keep a release's moving pointers to their own five minutes: the install script, the manifest and latest forbid serving them stale, and the edge's day-long stale window honours that
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by oscabriel · committed by oscabriel · parent 191a15d · Browse files · 4 files·+20 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+20 added−6 removed
- tests:+9 added−4 removed
- other:+11 added−2 removed
Provenance
- Commit
317e880- Tree
abc24a1- Author
oscabriel <oscarhernandeziv@gmail.com>- Committer
oscabriel <oscarhernandeziv@gmail.com>- Parent
191a15d
4 files changed+20 added−6 removed
modified:apps/platform/src/releases.ts+2 added-1 removed
86 unmodified lines87 const LATEST = "latest";88 89 const FOREVER = "public, max-age=31536000, immutable";90 91+// The install script, the manifest and `latest` move with each release, so no cache may serve one stale.91-const BRIEFLY = "public, max-age=300";92+const BRIEFLY = "public, max-age=300, must-revalidate";93 94 const NO_STORE = "no-store";95 96 const notFound = HttpServerResponse.empty({215 unmodified linesmodified:apps/platform/test/releases.test.ts+4 added-4 removed
105 unmodified lines106 cache: response.headers.get("cache-control"),107 status: response.status,108 type: response.headers.get("content-type"),109 }).toStrictEqual({110- cache: "public, max-age=300",110+ cache: "public, max-age=300, must-revalidate",111 status: 200,112 type: "text/x-shellscript; charset=utf-8",113 });114 expect(yield* textOf(response)).toBe(script("0.1.0"));74 unmodified lines189 status: reply.status,190 }))191 ).toStrictEqual([192 {193- cache: "public, max-age=300",193+ cache: "public, max-age=300, must-revalidate",194 location: `/releases/0.1.0/${linux}`,195 status: 302,196 },197 {198- cache: "public, max-age=300",198+ cache: "public, max-age=300, must-revalidate",199 location: "/releases/0.1.0/SHA256SUMS",200 status: 302,201 },202 ]);14 unmodified lines217 cache: listed.headers.get("cache-control"),218 status: listed.status,219 type: listed.headers.get("content-type"),220 }).toStrictEqual({221- cache: "public, max-age=300",221+ cache: "public, max-age=300, must-revalidate",222 status: 200,223 type: "application/json",224 });225 expect(yield* Effect.promise(() => listed.json())).toStrictEqual(397 unmodified linesmodified:apps/web/src/server/edge-cache.ts+9 added-1 removed
33 unmodified lines343536373838394041424344454647484950515253545578 unmodified lines33 unmodified lines directivesOf(cacheControl).some( (directive) => directive === "private" || directive === "no-store" );
// Only a found page with an age of its own: a miss may be answered once it is made, and an immutable answer is never stale.// Only a found page with an age of its own: a miss may be answered once it is made, an immutable answer is never// stale, and one that forbids serving it stale (a release's moving pointers) is kept to its own word.const FORBIDS_STALE = new Set([ "must-revalidate", "proxy-revalidate", "no-cache",]);
const staleLonger = (cacheControl: string, status: number) => { const directives = directivesOf(cacheControl);
return status !== 200 || directives.includes("immutable") || directives.some((directive) => FORBIDS_STALE.has(directive)) || !directives.some((directive) => directive.startsWith("max-age=")) ? undefined : [ ...directives.filter(78 unmodified linesmodified:apps/web/test/edge-cache.test.ts+5 added
203 unmodified lines204 get("/raw"),205 answer({ "cache-control": "public, max-age=31536000, immutable" }),206 ],207 ["an answer with no age", get("/x"), answer({ "cache-control": "public" })],208+ [209+ "the install script, which forbids serving it stale",210+ get("/install.sh"),211+ answer({ "cache-control": "public, max-age=300, must-revalidate" }),212+ ],213 ] as const)(214 "gives the edge no longer window for %s",215 (_, request, response) => {216 expect(304 unmodified lines