docs: prefer native Workers Caching over legacy cloudflareCache() - #2277
docs: prefer native Workers Caching over legacy cloudflareCache()#2277scottbuscemi wants to merge 3 commits into
Conversation
The Cloudflare demo and cloudflareCache() JSDoc pointed agents and humans at the Cache API + zone REST purge path (CF_ZONE_ID tokens). Point demos/cloudflare and deploy docs at wrangler cache.enabled + cacheCloudflare() / cache.purge() instead, and mark the EmDash helper as legacy.
🦋 Changeset detectedLatest commit: 85973e6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 17 packages
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 |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-demo-cache | 85973e6 | Jul 29 2026, 09:08 PM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-playground | 85973e6 | Jul 29 2026, 09:09 PM |
JSDoc @deprecated alone is easy to miss; emit a one-time console.warn at config time pointing at cacheCloudflare() + wrangler cache.enabled.
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/auth-atproto
@emdash-cms/blocks
@emdash-cms/cloudflare
@emdash-cms/contentful-to-portable-text
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/plugin-cli
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/registry-verification
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-field-kit
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-demo-do | 85973e6 | Jul 29 2026, 09:13 PM |
Overlapping PRsThis PR modifies files that are also changed by other open PRs: This may cause merge conflicts or duplicated work. A maintainer will coordinate. |
There was a problem hiding this comment.
The approach is right: redirecting new sites toward native Cloudflare Workers Caching and explicitly deprecating the legacy cloudflareCache() helper is the correct fix for the confusion trap described. The demo, deploy docs, and helper JSDoc/changeset are aligned with the existing infra/cache-demo setup, and the @astrojs/cloudflare catalog versions already support cacheCloudflare() and Astro 7.
I checked the diff against the checked-out files, AGENTS.md, and the repo conventions. The docs and demo config changes look correct. One AGENTS.md convention issue slipped into the code change: the one-time deprecation warning uses a module-scope let singleton instead of the repo’s globalThis + Symbol.for pattern for shared state. That can produce duplicate warnings if Vite duplicates the module across chunks.
One note: the PR description says “no runtime behavior change,” but the new console.warn in cloudflareCache() is a small config-time behavior change (the changeset correctly captures it). Not a code bug, but worth aligning the description.
|
|
||
| export type { CloudflareCacheConfig }; | ||
|
|
||
| let deprecationWarned = false; |
There was a problem hiding this comment.
[needs fixing] New module-scope mutable state is introduced to deduplicate the deprecation warning.
AGENTS.md requires module-scope singletons to live on globalThis via a Symbol.for key, because Vite/Astro can duplicate modules across SSR chunks, turning a plain let into multiple independent variables (see packages/core/src/request-cache.ts and packages/core/src/request-context.ts). The same risk applies here: if this module is evaluated more than once, existing sites can see the warning multiple times.
Store the flag on globalThis instead:
| let deprecationWarned = false; | |
| const DEPRECATION_WARNED_KEY = Symbol.for( | |
| "@emdash-cms/cloudflare/cloudflareCache:deprecation-warned", | |
| ); | |
| const globalStore = globalThis as Record<symbol, boolean | undefined>; | |
| // eslint-disable-next-line typescript/no-unsafe-type-assertion -- globalThis |
Then update the if (!deprecationWarned) { deprecationWarned = true; ... } block to test and set globalStore[DEPRECATION_WARNED_KEY]. That preserves the existing one-time behavior while following the repo’s singleton-state convention.
What does this PR do?
Clears up a confusion trap:
demos/cloudflareandcloudflareCache()from@emdash-cms/cloudflarelooked like the canonical edge-cache setup, but they use the legacy Cache API + zone REST purge path (CF_ZONE_ID/CF_CACHE_PURGE_TOKEN). EmDash deploy docs already describe native Workers Caching ("cache": { "enabled": true }) as the preferred approach.This PR aligns the demo and docs with that preferred path and marks the EmDash helper as legacy so agents/humans stop copying the wrong pattern.
Changes
demos/cloudflare: switch tocacheCloudflare()from@astrojs/cloudflare/cache; add"cache": { "enabled": true }to wrangler; README documents preferred vs legacywrangler+cacheCloudflare+cache.purge()), comparison table vs legacycloudflareCache(), note that object cache (kvCache) is a separate layercloudflareCache()JSDoc / export comment:@deprecatedguidance pointing at native Workers CachingNo runtime behavior change for existing sites that already use
cloudflareCache().Closes #
Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runmessages.pochanges except in translation PRs — a workflow extracts catalogs on merge tomain.AI-generated code disclosure
Screenshots / test output
n/a — docs + demo config comments only.
Try this PR
Open a fresh playground →
A full working EmDash site, deployed from this branch. Each visit gets its own session-scoped sandbox: no login needed and no shared state. Try the admin, edit content, hit the public site.
Tracks
docs/clarify-workers-cache. Updated automatically when the playground redeploys.