Skip to content
Myr

Merge perf/edge-stale into main

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by oscabriel · committed by oscabriel · parents f872f03, cdfd323 · Browse files · 2 files+80 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+80 added−1 removed

  • tests:+52 added−1 removed
  • other:+28 added−0 removed

2 files+80 added−1 removed

modified:apps/web/src/server/edge-cache.ts+28 added
modified:apps/web/test/edge-cache.test.ts+52 added-1 removed
8 unmodified lines
9import { forwarded } from "../src/features/agents/forward.ts";10import { backend } from "../src/server/backend.ts";11import { branchPage, personalPage } from "../src/server/cache-headers.ts";12import {13 EDGE_STALE_SECONDS,14 edgeEntry,15 forTheEdge,16 KEPT_NOWHERE,17} from "../src/server/edge-cache.ts";
144 unmodified lines
162163 expect([164 response.headers.get("cdn-cache-control"),165 response.headers.get("cloudflare-cdn-cache-control"),165 ]).toStrictEqual([null, null]);166 ]).toStrictEqual([167 null,168 `public, max-age=30, stale-while-revalidate=${EDGE_STALE_SECONDS}`,169 ]);170 });171172 it.each([173 ["a page at main", branchPage, "public, max-age=30"],174 [175 "an agent's document",176 { "cache-control": "public, max-age=60" },177 "public, max-age=60",178 ],179 ] as const)(180 "serves %s stale at the edge for a day while it reads it again, and tells the browser what the route said",181 (_, headers, fresh) => {182 const response = forTheEdge(get("/oscabriel/datekit"), answer(headers));183184 expect({185 browser: response.headers.get("cache-control"),186 edge: response.headers.get("cloudflare-cdn-cache-control"),187 }).toStrictEqual({188 browser: new Headers(headers).get("cache-control"),189 edge: `${fresh}, stale-while-revalidate=86400`,190 });191 }192 );193194 it.each([195 ["a page about its reader", get("/inbox"), answer(personalPage)],196 [197 "a page asked for with a session",198 get("/oscabriel/datekit", { cookie: SIGNED_IN }),199 answer(branchPage),200 ],201 ["a page not found", get("/nowhere"), answer(branchPage, 404)],202 [203 "a raw file at a commit",204 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 ] as const)(209 "gives the edge no longer window for %s",210 (_, request, response) => {211 expect(212 forTheEdge(request, response).headers.get(213 "cloudflare-cdn-cache-control"214 )215 ).toBeNull();216 }217 );218219 it.effect("comes back with its status, its other headers and its body", () =>220 Effect.gen(function* () {221 const response = forTheEdge(222 get("/nowhere"),
293 unmodified lines