Skip to content

Fix cache key collisions, HTTP scheme mixing, and Vary ambiguity#73

Merged
aui merged 4 commits into
mainfrom
feat/cache-key-overhaul
Jun 17, 2026
Merged

Fix cache key collisions, HTTP scheme mixing, and Vary ambiguity#73
aui merged 4 commits into
mainfrom
feat/cache-key-overhaul

Conversation

@aui

@aui aui commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

This is a major release that overhauls cache key generation to fix correctness and HTTP alignment issues:

  • Reduce wrong cache hits from digest collisions — cookie/header/device values now share one standard SHA-1 digest over a canonical string, instead of per-value truncated digests that could collide at scale.
  • Stop http and https from sharing the same entry — URL scheme is included in default keys (RFC 9111 URI identity).
  • Make Vary-aware keys unambiguous — explicit |v| / |vary| suffixes so base keys, Vary metadata, and variants cannot be parsed incorrectly.
  • Keep keys debuggable without exposing secrets — fragment key names stay visible (#cookie:a|header:x-id@…); only normalized values are digested.
  • Align cache lookup options with Workers Cache APImatch() / delete() support ignoreMethod only; ignore query strings via cacheKeyRules.search: false, bypass Vary via sharedCache.ignoreVary.

Also includes compiled cache-key rules with a sync fast path, per-request header/cookie context sharing, tightened public exports, and expanded test coverage (~98.8% statements).

Breaking changes

  • Existing cache entries miss until they expire or are revalidated.
  • Default keys now include scheme (https://…); set scheme: false for the previous host-first shape.
  • Remove cacheKeyPartDefiners / SharedCacheKeyPartDefiners; use built-in cacheKeyRules only.

Test plan

  • pnpm test (331 tests, ~98.8% statement coverage)
  • Verify cache hit/miss after deploy with new key format
  • Confirm reverse-proxy setups using scheme: false if needed

Adopt scheme-aware URL keys, SHA-1 fragment digests, clearer Vary delimiters, compiled key rules with sync fast path, and a tightened public export surface.
@changeset-bot

changeset-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f6926f4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@web-widget/shared-cache Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.78024% with 20 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/cache-key.ts 97.59% 15 Missing and 3 partials ⚠️
src/cache.ts 97.26% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@aui aui changed the title Overhaul cache key generation for HTTP alignment Fix cache key collisions, HTTP scheme mixing, and Vary ambiguity (major) Jun 17, 2026
@aui aui changed the title Fix cache key collisions, HTTP scheme mixing, and Vary ambiguity (major) Fix cache key collisions, HTTP scheme mixing, and Vary ambiguity Jun 17, 2026
@aui aui merged commit 4b5004c into main Jun 17, 2026
3 checks passed
@aui aui deleted the feat/cache-key-overhaul branch June 17, 2026 11:23
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.

1 participant