feat(cloudflare): Workers Cache support via cache prop on Worker - #1458
Merged
Merged
Conversation
Adds a `cache?: boolean | WorkerCacheOptions` prop to Worker that enables Workers Cache (https://developers.cloudflare.com/workers/cache/) — the Worker-owned edge cache in front of fetch() invocations — by setting `cache_options: { enabled, cross_version_cache }` in the upload metadata, matching the wire format wrangler >= 4.69 uploads. Includes an e2e test asserting repeat requests are served from cache (stable invocation id) and that ctx.cache.purge({ tags }) invalidates entries, plus a local-mode test that the prop no-ops in Miniflare, and a docs page. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
commit: |
Contributor
🚀 Website Preview DeployedYour website preview is ready! Preview URL: https://0a8abd21-alchemy-website.alchemy-run.workers.dev This preview was built from commit 5a2eb9d 🤖 This comment will be updated automatically when you push new commits to this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Adds support for Workers Cache — the Worker-owned edge cache that serves cached responses without invoking your Worker — mirroring the design already shipped for Effect-based Workers in #752 (
Cloudflare.cache()/ thecacheprop, see https://alchemy.run/cloudflare/compute/cache/).Usage
Caching is controlled by standard response headers, and entries can be purged at runtime:
What changed
Workergainscache?: boolean | WorkerCacheOptions({ enabled?, crossVersionCache? });trueis shorthand for{ enabled: true }.prepareWorkerMetadatamaps it tocache_options: { enabled, cross_version_cache }in the upload metadata — the snake_case wire shape wrangler ≥ 4.69 uploads (verified live in feat(cloudflare/workers): add cache_options to putScript metadata distilled#364).providers/cloudflare/cache.md.alchemy/test/cloudflare/cache.test.ts):Cache-Control: public, max-age=300— repeat fetches must return the same UUID (served from cache without invoking the Worker), thenctx.cache.purge({ tags })must produce a fresh one. Polls to absorb edge propagation.cache: truedeploys in Miniflare and no-ops (Workers Cache is not emulated locally).Notes for reviewers
CLOUDFLARE_API_KEYrejected, all OAuth refresh tokensinvalid_grant). The local test and typecheck pass; the metadata wire shape matches what distilled#364 verified live.wrangler.jsonintentionally does not emit acachefield yet: the repo pins wrangler 4.41, whose config schema predatescache(added in 4.69) and would warn on the unknown key.🤖 Generated with Claude Code