Skip to content

fix(astro-renderer): vary site Worker responses by host - #63

Merged
Madraka merged 1 commit into
mainfrom
fix/cache-vary-host
Oct 21, 2026
Merged

Madraka merged 1 commit into
mainfrom
fix/cache-vary-host

Conversation

@Madraka

@Madraka Madraka commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Fixes #62.

Workers Cache keys by path, not hostname, and answers before the Worker runs (docs). Every host routed to one site Worker therefore shared one cache entry per path.

  • Every site Worker response carries Vary: Host (merged into an existing Vary; Vary: * left alone) — cache-vary.ts, applied once in createSiteWorker's fetch.
  • Redirect-host 301s (domain: redirect www (or another host) to the primary domain #49) are cloudflare-cdn-cache-control: no-store as well.
  • RFC-0034: corrected its "the cache key already contains the host" assumption.

Verified on a real deployment

A throwaway deployment with two custom domains, cachetest.cloudhal.dev (site) and cachetest-www.cloudhal.dev (redirect), purged before each order:

main this PR
www first, then site / www 301 MISS, site 301 HIT (loop) www 301 BYPASS, site 200
site first, then www / site 200, www 200 HIT (no redirect) site 200, www 301 BYPASS
site / repeated HIT HIT after the first fills (age grows)

Tests: cache-vary.test.ts, host-redirect.test.ts; astro-renderer suite 255/255.

🤖 Generated with Claude Code

Workers Cache keys by path, not hostname, and answers before the Worker
runs. Every host routed to one site Worker shared one cache entry per path:
a redirect host's 301 (#49) was served on the site's own domain (a loop on
cloudhal.com's home page), and RFC-0034's multi-site Workers could serve
one site's cached page on another site's host.

- Every response from the site Worker carries `Vary: Host` (merged into an
  existing Vary), so the cache keeps one variant per host.
- Redirect-host 301s are `cloudflare-cdn-cache-control: no-store`.
- RFC-0034: corrected the "cache key contains the host" assumption.

Verified on a test deployment with two custom domains: before, the 301
and the 200 leaked between hosts in both orders; after, each host gets its
own answer, and the site's pages are still cached (HIT).

Fixes #62

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Madraka <[email protected]>
@Madraka
Madraka merged commit 9a33594 into main Oct 21, 2026
4 checks passed
@Madraka
Madraka deleted the fix/cache-vary-host branch October 21, 2026 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Site Worker edge cache is keyed by path, not host: redirect hosts loop, multi-site can serve another site's page

1 participant