Repository navigation
docs: add a Route Caching guide - #1820
Conversation
|
@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-test
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/registry-loader
@emdash-cms/registry-moderation
@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: |
There was a problem hiding this comment.
The change is the right idea: a dedicated edge-caching guide fills a real gap linked to discussion #1742, and the new page is correctly registered in the sidebar and cross-linked. The writing is clear and the opt-out sections (preview, errors, redirects) are valuable.
However, the implementation example for cache purging is not correct for the current codebase. The purge plugin imports { cache } from cloudflare:workers and calls cache.purge({ tags }), but that export/method is not present in the repo's generated Worker types (docs/worker-configuration.d.ts). The Workers runtime types defined here expose the standard Web Cache API (Cache with match/put/delete) via the global caches object—not a cloudflare:workers cache object with purge. Following this snippet will produce a TypeScript error and, in all likelihood, no purge at runtime, leaving the guide's central promise unfulfilled.
Compounding this, the project already ships and dogfoods a Cloudflare route-cache provider (cloudflareCache() from @emdash-cms/cloudflare) in demos/cloudflare/astro.config.mjs, and EmDash core's content API routes already call context.cache.invalidate({ tags }) expecting a provider that implements that interface. Recommending Astro's cacheCloudflare() without mentioning EmDash's integrated provider is a docs gap and may steer users away from the path the rest of the project is built around.
On the positive side, the claim that toolbar-injected editor responses are marked private, no-store is correct (see packages/core/src/astro/middleware/request-context.ts).
I checked the diff, the new edge-cache page, the updated cloudflare/object-cache pages, the generated worker-configuration.d.ts, the project's own cache provider implementation, and the existing demos.
| try { | ||
| // `cloudflare:workers` exists only at Worker runtime; a top-level | ||
| // import would break `astro dev` and the build. | ||
| const { cache } = await import("cloudflare:workers"); |
There was a problem hiding this comment.
[needs fixing] This example tells readers to import cache from cloudflare:workers and call cache.purge({ tags }), but that export/method is not present in the repo's generated Worker types (docs/worker-configuration.d.ts). The types here only define the standard Web Cache API (Cache / caches) with match, put, and delete. A reader following this snippet will get a type error and, almost certainly, no cache purge at runtime — the page's main promise (purge-on-publish) will not work.
EmDash already provides a working alternative: cloudflareCache() from @emdash-cms/cloudflare, used in demos/cloudflare/astro.config.mjs, which purges tags via the Cloudflare REST API using CF_ZONE_ID and CF_CACHE_PURGE_TOKEN. That provider also satisfies the context.cache.invalidate({ tags }) calls already made by EmDash's content API routes. Prefer documenting that path, or at minimum confirm and document the exact beta API shape and compatibility requirements if Astro's cacheCloudflare() is intended.
| const { cache } = await import("cloudflare:workers"); | |
| // Purge via the configured cache provider. EmDash's cloudflareCache() | |
| // provider invalidates tags through the Cloudflare REST API using | |
| // CF_ZONE_ID / CF_CACHE_PURGE_TOKEN; replace this with your provider's | |
| // actual invalidation call. The current @cloudflare/workers-types in this | |
| // repo do not expose cache.purge on cloudflare:workers. | |
| // Example: | |
| // const provider = await import("@emdash-cms/cloudflare/cache/runtime"); | |
| // await provider.default(config).invalidate({ tags }); |
There was a problem hiding this comment.
Resolved by removing the plugin recipe entirely — purge-on-publish is built into EmDash core (content API routes + scheduled-publish sweep invalidate [collection, id] tags), so the guide now documents that and the matching tag convention instead. The cloudflareCache() REST-purge path isn't documented as the alternative since it's being deprecated (see thread above); for what it's worth, cache.purge({ tags }) from cloudflare:workers does work at runtime now that the API is GA, the generated types in this repo are just older.
| output: "server", | ||
| adapter: cloudflare(), | ||
| cache: { | ||
| provider: cacheCloudflare(), |
There was a problem hiding this comment.
[suggestion] The guide recommends Astro's cacheCloudflare() provider without mentioning that EmDash ships its own Cloudflare route-cache provider, cloudflareCache() from @emdash-cms/cloudflare. The project's primary Cloudflare demo (demos/cloudflare/astro.config.mjs) uses cloudflareCache() with routeRules, and EmDash's content API routes already invalidate route-cache tags through that interface. Consider adding a note that cloudflareCache() is the stable, integrated EmDash option and explaining when to choose Astro's beta cacheCloudflare() approach.
| provider: cacheCloudflare(), | |
| Register the Cloudflare cache provider and declare which routes may be cached, for how long, and under which tags. EmDash also provides `cloudflareCache()` from `@emdash-cms/cloudflare`, which uses the Cloudflare REST purge API and is the provider used by the project's Cloudflare demo; the example below uses Astro's `cacheCloudflare()` and its beta tag-purge API. |
There was a problem hiding this comment.
I will be deprecating the emdash route cache provider.
There was a problem hiding this comment.
Understood — the guide now recommends Astro's cacheCloudflare() only, with a one-line note that cloudflareCache() predates Astro route caching and is deprecated.
ascorbic
left a comment
There was a problem hiding this comment.
Quite a few of the things in here need to be checked against the live version
|
|
||
| Routes without a matching rule are stamped `Cloudflare-CDN-Cache-Control: no-store`, so the admin panel, authenticated routes, and mutating API endpoints stay uncached without extra configuration. Only list routes that are safe to serve identically to every visitor. | ||
|
|
||
| ## Purge on publish |
There was a problem hiding this comment.
This is already built-in. It doesn't need a plugin
There was a problem hiding this comment.
You're right — rewritten. The section is now "Purge on publish is built-in" and documents the [collection, id] tag invalidation done by the content API routes and the scheduled-publish sweep, plus the tag convention that makes route rules line up with it (tags must use collection names or the built-in purge won't match). The plugin recipe is gone.
| output: "server", | ||
| adapter: cloudflare(), | ||
| cache: { | ||
| provider: cacheCloudflare(), |
There was a problem hiding this comment.
I will be deprecating the emdash route cache provider.
|
|
||
| <Aside type="caution"> | ||
| The Workers Cache and its tag-based purge API (`cache.purge` from | ||
| `cloudflare:workers`) are in beta and not available on every account. Check |
There was a problem hiding this comment.
They are generally available now
There was a problem hiding this comment.
Fixed — caution removed, the guide no longer mentions beta.
|
|
||
| ```jsonc title="wrangler.jsonc" | ||
| { | ||
| "cache": { "enabled": true }, |
There was a problem hiding this comment.
This is added automatically if you enable the Cloudflare cache
There was a problem hiding this comment.
Fixed — the manual wrangler step is removed. The guide now notes the adapter writes "cache": { "enabled": true } into the generated Wrangler config when a cache provider is configured (verified: it lands in dist/server/wrangler.json via the redirected config in .wrangler/deploy/config.json).
|
|
||
| ### Preview links | ||
|
|
||
| Preview URLs carry a signed token as a query parameter, and each query variant is cached separately — a preview response would otherwise sit in the edge cache under its token URL after the token expires. Disable caching when draft content is served: |
There was a problem hiding this comment.
I think preview links will always have a cookie set, which would disable caching
There was a problem hiding this comment.
I tested this against the live version to be sure. Setup: a stock EmDash install (emdash 0.27.0, Astro 7.0.6, @astrojs/cloudflare 14.1.1, deployed with Wrangler 4.107) with nothing added except the config this guide recommends — cacheCloudflare() as provider plus routeRules for the public routes.
Preview links don't set a cookie: the token travels in the ?_preview= query param and the response carries no Set-Cookie. And a cookie wouldn't help anyway — the Workers Cache doesn't vary on or bypass for the Cookie request header (a request with a session cookie against a cached route is served the shared cf-cache-status: HIT).
Repro on the fresh deploy, anonymous requests against a valid preview URL:
request 1: cf-cache-status: MISS cache-control: private, no-store
request 2: cf-cache-status: HIT age: 3 cache-control: private, no-store
request 3: cf-cache-status: HIT age: 3 cache-control: private, no-store
The middleware's private, no-store is set correctly, but it only governs browsers/downstream — the Workers Cache follows the route rule's Cloudflare-CDN-Cache-Control, so the preview variant is stored at the edge under its token URL. Once cached, hits never invoke the Worker: no token verification runs, and the response (draft content, when previewing a draft) stays reachable until the entry expires or is purged — including after the token itself has expired.
So the opt-out in this section is load-bearing, and arguably core should handle it: the preview branch in request-context.ts (and the toolbar-inject path) could call context.cache.set(false) alongside setting Cache-Control. Happy to send that as a small follow-up PR if you want.
|
Pushed a revision addressing the review:
Docs build is green locally. |
There was a problem hiding this comment.
This is a well-targeted docs-only follow-up. The previous review’s central concern — an incorrect cloudflare:workers cache.purge() snippet that did not match the repo’s types — is fully resolved: the new page drops the manual purge code and correctly states that EmDash’s content API routes call the configured route cache provider’s invalidate({ tags }) on save/publish/unpublish/delete/restore/duplicate/schedule. The previous docs gap around EmDash’s own cloudflareCache() provider is also addressed with a deprecation/recommendation note.
What I checked:
- The new
docs/src/content/docs/deployment/edge-cache.mdxpage, plus the sidebar registration indocs/astro.config.mjs, the updated cross-links inobject-cache.mdxandcloudflare.mdx. - The relevant runtime code:
packages/core/src/astro/middleware/request-context.tsconfirms preview and toolbar-injected responses are stampedCache-Control: private, no-store. - The content API routes (e.g.
packages/core/src/astro/routes/api/content/[collection]/[id].ts,publish.ts,unpublish.ts,restore.ts,duplicate.ts,schedule.ts,discard-draft.ts,permanent.ts) confirmcache?.invalidate({ tags: [collection, id] })is invoked after writes. packages/cloudflare/src/worker.tsconfirms the Cloudflarescheduled()handler passesonPublishedtorunScheduledTasks, so scheduled publishes do purge tags on Cloudflare deployments.getEmDashEntryfrompackages/core/src/query.tsdoes return{ entry, isPreview, cacheHint }, so the preview opt-out snippet is valid.- The
docspackage is private, so no changeset is required for this PR.
Headline conclusion: the approach is now sound and the page matches the implementation. I did not find any verifiable errors, missing links, or AGENTS.md convention violations. There is one caveat I could not confirm statically: the docs assume that @astrojs/cloudflare/cache’s cacheCloudflare() provider supports tag-based invalidation out of the box (or validated that it does). Since this is Astro’s built-in provider and the page builds successfully, I have no reason to doubt it, but I could not exercise the runtime purge behavior in this static review.
|
This PR has been inactive for 14 days. It will be closed automatically in 7 days if there is no further activity. If you're still working on this, please push an update or leave a comment. |
There was a problem hiding this comment.
This remains the right docs-only follow-up to EmDash’s edge-caching work: it adds a dedicated Workers Cache guide, fixes the stale cross-link from the object-cache page, and links the new page from the Cloudflare overview. I treated this as a re-review, so I did not re-raise the prior findings that were addressed (the Astro.cache?.enabled guard, the four chrome helper mentions, and the purge-on-publish wording).
I re-verified the new documentation against the implementation:
- Cache tags for chrome resources are exactly the documented
emdash:*shape inpackages/core/src/cache/chrome-tags.ts, and theget*WithCacheHinthelpers inmenus/index.ts,settings/index.ts,taxonomies/index.ts, andwidgets/index.tsexpose those tags ascacheHint. - Content API routes in
packages/core/src/astro/routes/api/content/**invalidate[collection, id]on save/update/delete/discard-draft/publish/unpublish/restore/schedule/permanent-delete and[collection]on create/duplicate. Scheduled publishing purges the same tags frompackages/cloudflare/src/worker.tsviainvalidatePublishedTags(). - Preview-token,
_edit, and toolbar-injected responses are opted out of the route cache inpackages/core/src/astro/middleware/request-context.ts; valid previews and toolbar-injected responses also getCache-Control: private, no-store. - Admin/API responses use
API_CACHE_HEADERS(private, no-store) frompackages/core/src/api/error.ts.
No blocking issues. I have one small wording suggestion on the Cloudflare overview page: it still says invalidation “uses cache.purge()”, which is no longer the user-facing API now that the page emphasizes EmDash’s built-in invalidation.
Findings
-
[suggestion]
docs/src/content/docs/deployment/cloudflare.mdx:141This step still says invalidation “uses
cache.purge()”, but the rest of the page now tells readers that EmDash invalidates entries automatically through the provider. The previouscache.purge()recipe was removed for that reason. Rephrase the step so it doesn’t point readers at a platform method they no longer need to call.1. Use Astro's Cloudflare cache provider so route rules and `Astro.cache` set cache headers and the provider can invalidate entries when content changes.
There was a problem hiding this comment.
This is the right docs-only follow-up to EmDash’s edge-caching work: it adds a dedicated Workers Cache guide, fixes the stale cross-link from the object-cache page, and links the new page from the Cloudflare overview. I treated this as a re-review, so I did not re-raise the prior findings that were addressed (the Astro.cache?.enabled guard, the four chrome helper mentions, and the purge-on-publish wording).
I re-verified the new documentation against the implementation:
- Content API routes in
packages/core/src/astro/routes/api/content/**invalidate[collection, id]on update/delete/publish/unpublish/restore/schedule/unschedule/discard-draft/permanent-delete, and[collection]on create/duplicate. The scheduled-publish sweep inpackages/cloudflare/src/worker.tspurges the same tags throughinvalidatePublishedTags(). - Cache tags for chrome resources are exactly the documented
emdash:*shape inpackages/core/src/cache/chrome-tags.ts, and the write routes for site settings, menus, taxonomies (defs + terms + reorder), and widget areas all callcache.invalidate({ tags: [...] })with those tags. - Preview-token,
_edit, and toolbar-injected responses are opted out of the route cache inpackages/core/src/astro/middleware/request-context.ts; valid previews and toolbar-injected responses also getCache-Control: private, no-store. - Admin/API responses use
API_CACHE_HEADERS(private, no-store) frompackages/core/src/api/error.ts.
The remaining issue is a documentation gap the PR description claims is already filled: the new guide never tells readers that EmDash previously shipped (and has removed/deprecated) its own cloudflareCache() provider, which is documented as removed in upgrade-to-v1.mdx. Adding that one-line note avoids readers discovering the legacy path elsewhere and wondering why this guide doesn’t mention it.
I also noticed that upgrade-to-v1.mdx still frames Workers Cache purging as a manual cache.purge() call; now that the edge-cache page documents EmDash’s built-in invalidation, the upgrade doc should point there instead. That’s outside the diff, so I left it as a summary note rather than a line comment.
|
|
||
| The [object cache](/deployment/object-cache/) stores query results, but every request still renders HTML inside the Worker. Edge caching stores the rendered HTML response itself in the [Cloudflare Workers Cache](https://developers.cloudflare.com/workers/cache/), so a cache hit is served at the edge and never invokes the Worker. Combined with cache tags and EmDash's built-in purging, pages stay cached for days while a publish becomes visible within seconds. | ||
|
|
||
| This guide uses [Astro's route caching](https://docs.astro.build/en/guides/caching/) with the Cloudflare cache provider, and applies to Cloudflare deployments only. The two caches are complementary: the edge cache serves repeat requests, the object cache makes the remaining renders cheap. |
There was a problem hiding this comment.
[suggestion] The intro tells readers to use Astro’s cacheCloudflare() but never mentions that EmDash previously shipped its own cloudflareCache() provider. A reader arriving from an old demo, a migration guide, or search may not realize cloudflareCache() has been replaced, and upgrade-to-v1.mdx already documents it as removed. Add a one-line note so the page matches the PR description and steers readers away from the legacy API.
| This guide uses [Astro's route caching](https://docs.astro.build/en/guides/caching/) with the Cloudflare cache provider, and applies to Cloudflare deployments only. The two caches are complementary: the edge cache serves repeat requests, the object cache makes the remaining renders cheap. | |
| This guide uses [Astro's route caching](https://docs.astro.build/en/guides/caching/) with the Cloudflare cache provider, and applies to Cloudflare deployments only. EmDash's own `cloudflareCache()` provider from `@emdash-cms/cloudflare` was removed in v1; new sites should use `cacheCloudflare()` instead. See [Upgrade to v1](/upgrade-to-v1/#removed-cloudflarecache) if you are migrating from the old provider. The two caches are complementary: the edge cache serves repeat requests, the object cache makes the remaining renders cheap. |
|
Thanks, both done: the Edge Caching guide now notes that the pre-1.0 |
There was a problem hiding this comment.
This is the right docs-only follow-up to EmDash’s edge-caching work and the prior review issues are addressed: the Astro.cache?.enabled guard is present in both examples, all four chrome cache-hint helpers are named, the legacy cloudflareCache() provider is documented as removed with a link to the upgrade guide, and the beta warning was correctly dropped after the collaborator confirmed the API is GA.
I re-verified the new Edge Caching guide against the implementation:
- Content API invalidation:
packages/core/src/astro/routes/api/content/[collection]/[id].tsinvalidates[collection, resolvedId]on PUT/DELETE;publish.ts,unpublish.ts,restore.ts,schedule.ts,unschedule.ts,discard-draft.ts, andpermanent.tsall do the same.index.ts(create) andduplicate.tsinvalidate[collection]. - Scheduled publishing:
packages/cloudflare/src/worker.tspassesinvalidatePublishedTagstorunScheduledTasks, which purges[collection, id]for items promoted by the cron sweep. - Chrome tags:
packages/core/src/cache/chrome-tags.tsemitsemdash:settings,emdash:menu:{name},emdash:taxonomy:{name}, andemdash:widget-area:{name}. The settings, menu, taxonomy, and widget-area write routes all callcache.invalidate({ tags: [...] })with the matching tag, and the corresponding read helpers (getMenuWithCacheHint,getSiteSettingsWithCacheHint,getTaxonomyTermsWithCacheHint,getWidgetAreaWithCacheHint) return cache hints using the same tags. - Opt-outs:
packages/core/src/astro/middleware/request-context.tsopts?_preview=,?_edit, and toolbar-injected responses out of the route cache and setsCache-Control: private, no-storefor valid previews and toolbar responses.packages/core/src/api/error.tssetsAPI_CACHE_HEADERStoprivate, no-storefor API responses. - Sidebar/cross-links: the new page is registered after Object Cache,
object-cache.mdxnow links to it,cloudflare.mdxlinks to it, andupgrade-to-v1.mdxpoints to it for the purge-on-publish behavior.
The only remaining item is a wording tweak: the intro says the object cache "makes the remaining renders cheap," which is imprecise because anonymous route-cache fills deliberately bypass the object cache (see routeCacheFill in the middleware and the bypass in packages/core/src/object-cache/index.ts) so a page purged after a publish is not rebuilt from a stale KV snapshot. object-cache.mdx already documents this nuance; a one-line clarification keeps the Edge Caching page from implying cache misses are object-cached.
| --- | ||
|
|
||
| The [object cache](/deployment/object-cache/) stores query results, but every request still renders HTML inside the Worker. Edge caching stores the rendered HTML response itself in the [Cloudflare Workers Cache](https://developers.cloudflare.com/workers/cache/), so a cache hit is served at the edge and never invokes the Worker. Combined with cache tags and EmDash's built-in purging, pages stay cached for days while a publish becomes visible within seconds. | ||
|
|
There was a problem hiding this comment.
[suggestion] The intro frames the edge and object caches as complementary — edge serves repeat requests, object cache makes remaining renders cheap. I verified in packages/core/src/astro/middleware/request-context.ts and packages/core/src/object-cache/index.ts that when both caches are configured, anonymous route-cache fills set routeCacheFill: true and deliberately bypass the object cache so a page purged after a content change is not rebuilt from a stale KV snapshot. object-cache.mdx already documents this nuance, so add it here to avoid implying that edge-cache misses are object-cached.
| The two caches are complementary: the edge cache serves repeat requests, the object cache keeps database reads cheap for the renders that use it. |
Or, if you prefer to keep the punchier framing with a parenthetical note:
| The two caches are complementary: the edge cache serves repeat requests, the object cache makes the remaining renders cheap (route-cache fills bypass it to guarantee freshness; see [Object Cache](/deployment/object-cache/)). |
There was a problem hiding this comment.
This is the right docs-only follow-up to EmDash's edge-caching work. After re-reading the updated Edge Caching guide and the related Cloudflare/Object Cache/upgrade pages, all of the prior review items are addressed and the new page matches the implementation.
What I re-verified:
- Object-cache wording: the intro now correctly notes that renders which fill the edge cache bypass the object cache, so a purged page is not rebuilt from a stale KV snapshot (
packages/core/src/object-cache/index.tsshouldBypass()includesrouteCacheFill === true). Astro.cache?.enabledguard: present in both the entry example and the 404 example inedge-cache.mdx.- All four chrome cache-hint helpers named:
getMenuWithCacheHint,getSiteSettingsWithCacheHint,getTaxonomyTermsWithCacheHint, andgetWidgetAreaWithCacheHintare all documented and exported fromemdash. - Legacy
cloudflareCache()provider: documented as removed with a link to the upgrade guide. The@emdash-cms/cloudflarepackage no longer exports it. - Beta warning: correctly dropped after the collaborator confirmed the API is GA.
- Content API invalidation: every write route I checked purges the right tags:
[collection, id]on PUT/DELETE/publish/unpublish/restore/schedule/unschedule/discard-draft/permanent, and[collection]on create/duplicate (with schedule handled in a single file for both POST/DELETE). - Chrome cache invalidation: settings, menu, taxonomy, and widget-area write routes all invalidate the matching
emdash:*tags returned by the cache-hint helpers. - Scheduled publishing:
packages/cloudflare/src/worker.tspassesinvalidatePublishedTagstorunScheduledTasks, which purges[collection, id]for items promoted by the cron sweep. - Opt-outs: preview-token,
_edit, and toolbar-injected responses are opted out of the route cache; valid previews and toolbar responses also getCache-Control: private, no-store. API responses carry the same header viaAPI_CACHE_HEADERS.
I did not find any false technical claims or outdated commands. The cross-links to the upgrade guide and the object-cache "What gets cached" anchor resolve. No changeset is needed because this is a docs-only change that doesn't touch a published package.
Findings: none.
danielmlr
left a comment
There was a problem hiding this comment.
Thanks for the work on this. The EmDash side is right: the content and chrome invalidation tags, the cron purge, the preview opt-out and the Wrangler injection all match current main, the branch merges cleanly, and the docs build locally with the anchors resolving.
Two claims don't hold and one caveat is missing, all of which readers would act on (details inline):
- Editors and cached pages:
toolbar: "client"(#1886) is the fix; in server mode the edge cache ignores the edit-mode cookie. - Routes without a rule: any
Astro.cache.set(cacheHint)yieldsCloudflare-CDN-Cache-Control: public, notno-store. - Purge rate limit: Workers Cache purges use the Free-tier limit and fail silently, which matters next to a one-day
maxAge.
Smaller points:
- Each deploy starts with an empty edge cache, because the Worker version is part of the cache key. Worth a sentence.
- The
routeRulesexample caches/sitemap.xmlbut not the per-collection/sitemap-[collection].xmlfiles. - Byline and media edits don't purge anything, which readers of "Purge on publish is built-in" may assume.
- Outside the diff, in
cloudflare.mdx: item 1 under "Two things to know" (heuristic freshness) conflicts with theno-storeclaim here, and item 2 (editors get the cached variant) should mentiontoolbar: "client". - The PR description still describes purging through
content:afterSave/content:afterDeletehooks and ticks the tests and changeset boxes, which are n/a for a docs-only change.
~ 🤖 Claude Code (Opus 5.5)
|
|
||
| ## Editors and cached pages | ||
|
|
||
| The edge cache stores one shared variant per URL. The editor toolbar is injected only into responses rendered for an authenticated editor, and those responses are marked `private, no-store` — they are never stored in a shared cache. An editor browsing the public site is therefore usually served the cached anonymous variant, without the toolbar. Preview links and edit mode force uncached renders and are unaffected. Improving the toolbar experience behind shared caches is tracked in [discussion #1742](https://github.com/emdash-cms/emdash/discussions/1742). |
There was a problem hiding this comment.
#1742 was closed by your #1886: toolbar: "client" keeps public HTML identical for everyone and gives editors an ?_edit URL that always renders fresh. I'd point readers to the toolbar section of /reference/configuration/ instead of the discussion.
"Preview links and edit mode force uncached renders" also only holds for edit mode in client mode. In the default server mode, edit mode is the emdash-edit-mode cookie. Workers Cache doesn't key on cookies and doesn't run the Worker on a hit, so an editor in edit mode on a cached URL gets the anonymous page.
~ 🤖 Claude Code (Opus 5.5)
|
|
||
| ### Preview and edit links are handled automatically | ||
|
|
||
| EmDash's middleware opts these responses out of the route cache itself, so no template code is needed: requests carrying a `?_preview=` token (valid or not — those URLs are per-token, and a cached draft would otherwise stay reachable after the token expires), `?_edit` URLs, and responses with the editor toolbar injected. Valid preview responses and toolbar-injected responses are additionally marked `Cache-Control: private, no-store` for browsers and downstream CDNs. |
There was a problem hiding this comment.
?_edit is only special when toolbar: "client" is set (request-context.ts: toolbarMode === "client" && url.searchParams.has(EDIT_PARAM)). Worth saying so here.
~ 🤖 Claude Code (Opus 5.5)
|
|
||
| The provider turns these rules into `Cloudflare-CDN-Cache-Control` and `Cache-Tag` response headers. The edge consumes both; clients never see them, and any `Cache-Control` header your pages set for browsers is unaffected. | ||
|
|
||
| Routes without a matching rule are stamped `Cloudflare-CDN-Cache-Control: no-store`, so the admin panel, authenticated routes, and mutating API endpoints stay uncached without extra configuration. Only list routes that are safe to serve identically to every visitor. |
There was a problem hiding this comment.
This only holds while the page doesn't call Astro.cache.set(). Astro's Cloudflare provider always includes public in the directive, and with no maxAge in the hint that's the whole directive. So a tags-only cacheHint on a route without a rule produces Cloudflare-CDN-Cache-Control: public plus Cache-Tag, and the adapter's no-store default no longer applies. Running Astro 7.3.2's AstroCache with the @astrojs/cloudflare 14.3.1 provider:
no rule, cacheHint only { 'cache-tag': 'emdash:settings,emdash:menu:primary,astro-path:/about', 'cloudflare-cdn-cache-control': 'public' }
I haven't checked this on a live deploy, but cloudflare.mdx already says Workers Cache applies heuristic freshness to responses without a lifetime, so such a page would be cached with no maxAge bound. The templates set settings and menu hints in Base.astro, so this reaches every page there. Either this paragraph needs the caveat, or the fix belongs in the templates or core. Your call which.
~ 🤖 Claude Code (Opus 5.5)
|
|
||
| ## Purge on publish is built-in | ||
|
|
||
| No plugin or hook is required. EmDash's content API routes invalidate the route cache whenever an entry changes: saving, publishing, unpublishing, deleting, or restoring an entry purges the tags `[collection, id]`, and scheduled publishing purges the same tags from the cron sweep. Creating or duplicating an entry purges the collection tag (the new entry has no cached pages yet). Any route rule tagged with the collection name (as above) is therefore refreshed within seconds of a publish, even with a long `maxAge`. |
There was a problem hiding this comment.
Workers Cache purges always use the Free-tier purge limit, whatever the plan: 5 requests per minute, bucket of 25, per account (purge, limits). A rate-limited purge returns success: false, which the Astro provider doesn't check, so the page stays stale until maxAge with no error anywhere. (I haven't seen this happen on a deploy; this is from the purge docs and the provider code.) Every save of live content costs one purge, including autosave on collections without revisions. Could you add that caveat here and tie the maxAge advice to it?
~ 🤖 Claude Code (Opus 5.5)
|
|
||
| The [object cache](/deployment/object-cache/) stores query results, but every request still renders HTML inside the Worker. Edge caching stores the rendered HTML response itself in the [Cloudflare Workers Cache](https://developers.cloudflare.com/workers/cache/), so a cache hit is served at the edge and never invokes the Worker. Combined with cache tags and EmDash's built-in purging, pages stay cached for days while a publish becomes visible within seconds. | ||
|
|
||
| This guide uses [Astro's route caching](https://docs.astro.build/en/guides/caching/) with the Cloudflare cache provider, and applies to Cloudflare deployments only. The two caches are complementary: the edge cache serves repeat requests, the object cache makes the remaining renders cheap. Renders that fill the edge cache skip the object cache and read from the database, so a purged page is never rebuilt from an older snapshot (see [What gets cached](/deployment/object-cache/#what-gets-cached)). |
There was a problem hiding this comment.
The next sentence says renders that fill the edge cache skip the object cache. With a cache provider configured, that is every anonymous render, not only those on routes with a rule (request-context.ts sets routeCacheFill, object-cache/index.ts shouldBypass). So "the object cache makes the remaining renders cheap" holds mainly for signed-in renders. Could you reword that clause?
~ 🤖 Claude Code (Opus 5.5)
|
|
||
| This guide uses [Astro's route caching](https://docs.astro.build/en/guides/caching/) with the Cloudflare cache provider, and applies to Cloudflare deployments only. The two caches are complementary: the edge cache serves repeat requests, the object cache makes the remaining renders cheap. Renders that fill the edge cache skip the object cache and read from the database, so a purged page is never rebuilt from an older snapshot (see [What gets cached](/deployment/object-cache/#what-gets-cached)). | ||
|
|
||
| EmDash versions before 1.0 shipped their own `cloudflareCache()` provider from `@emdash-cms/cloudflare`. It has been removed; if your config still imports it, see [Upgrade to EmDash 1.0](/upgrade-to-v1/#removed-cloudflarecache). |
There was a problem hiding this comment.
ascorbic asked for the earlier version of this note to go ("no need to mention it", 2026-09-10) and emdashbot later asked for it back. Since version differences belong in the upgrade guide, which already covers cloudflareCache(), I'd go with ascorbic and drop it.
~ 🤖 Claude Code (Opus 5.5)
|
|
||
| </Steps> | ||
|
|
||
| That's the whole setup: EmDash invalidates cached entries automatically when content changes (see [Edge Caching](/deployment/edge-cache/) for the tag convention). You only need to purge yourself for custom tags — for example a manual "clear everything" switch, using the platform's [cache purge API](https://developers.cloudflare.com/workers/cache/) from your Worker (no Cloudflare REST credentials needed). |
There was a problem hiding this comment.
"That's the whole setup:" can go. I'd link the purge API at https://developers.cloudflare.com/workers/cache/purge/. <Steps> now wraps a single item.
~ 🤖 Claude Code (Opus 5.5)
|
|
||
| 1. **Responses without a `Cache-Control` header are still cached.** Workers Cache applies RFC 9111 heuristic freshness — a `200` without any header is cached for 2 hours. Give every custom route an explicit `Cache-Control` (use `private, no-store` for anything session-dependent). | ||
| 2. **Cached pages are shared with logged-in editors.** The cache runs before your Worker, so it cannot bypass based on request cookies. A logged-in editor may receive the cached anonymous variant of a public page — without the visual editing toolbar — until the entry expires. Editor-rendered responses themselves are never stored (they carry `private, no-store`), so nothing leaks in the other direction. | ||
| 1. **A response with any cache hint is cacheable, even without a route rule.** The adapter marks responses that no route rule or `Astro.cache.set()` call made cacheable as `no-store`. A hint with tags but no `maxAge`, such as the site settings and menu hints a layout sets on every page, produces `Cloudflare-CDN-Cache-Control: public` without a lifetime, and Workers Cache then applies RFC 9111 heuristic freshness. Give every public route a rule, and keep session-dependent routes free of cache hints. |
There was a problem hiding this comment.
RFC 9111 heuristic freshness
Tell people what the actual values are, or link to the CF docs
| description: Cache rendered HTML in the Cloudflare Workers Cache and purge it by tag when content changes. | ||
| --- | ||
|
|
||
| The [object cache](/deployment/object-cache/) stores query results, but every request still renders HTML inside the Worker. Edge caching stores the rendered HTML response itself in the [Cloudflare Workers Cache](https://developers.cloudflare.com/workers/cache/), so a cache hit is served at the edge and never invokes the Worker. Combined with cache tags and EmDash's built-in purging, pages stay cached for days while a publish usually becomes visible within seconds (see [Purge rate limits](#purge-rate-limits)). |
There was a problem hiding this comment.
This shouldn't be written as a Cloudflare-specific guide. It uses Astro Route Caching, so is platform agnostic, and the guide shoudl use the Astro terminology.
Rebased onto current main and refreshed against the current code: preview/_edit/toolbar responses now opt out of the route cache in core middleware, so the manual opt-out section became 'handled automatically'; documents the cacheHint pattern (getEmDashEntry/getEmDashCollection, getMenuWithCacheHint, getSiteSettingsWithCacheHint) and the emdash:* chrome tags purged on settings/menu/taxonomy/widget-area writes. The cloudflare.mdx Workers Cache section that grew on main is kept, with a cross-link to the deeper guide.
…cacheHint helpers The Workers Cache section still told readers to wire up manual purging, which the new Edge Caching page makes unnecessary (built-in purge on content writes) — and the import shown doesn't typecheck against the repo's own cloudflare:workers declarations. Reframed as an optional custom-tag escape hatch. Also completes the cacheHint helper list with getTaxonomyTermsWithCacheHint and getWidgetAreaWithCacheHint.
… the built-in purge
…out of the route cache
What does this PR do?
Adds a deployment guide for caching rendered pages with Astro route caching, at
/deployment/route-caching/. It covers:memoryCache()on Node.js,cacheCloudflare()on Cloudflare, with a link to Astro's other adapter providers)routeRulesand the query helpers'cacheHint, and the tag convention EmDash's built-in invalidation relies ontoolbar: "client"helpsIt also adds the page to the docs sidebar, updates the Workers Cache section in
deployment/cloudflare.mdx(including the default lifetime a cache hint withoutmaxAgegets), fixes the cross-links inobject-cache.mdxandupgrade-to-v1.mdx, and clarifies in thetoolbarreference that signed-in renders stay out of Astro's route cache.I run EmDash on Cloudflare with the Workers Cache and had to piece this together from the Astro docs, the adapter source and EmDash's invalidation code. Editors behind a shared cache seeing stale pages also came up in discussion #1742.
The guide started as a Cloudflare-specific "Edge Caching" page and was reworked after review to use Astro's route caching terminology and treat Cloudflare as one provider.
Type of change
Your connection to this 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.Docs-only change (MDX and the sidebar entry), no package code touched, so typecheck, lint and tests don't apply and no changeset is needed. Every claim about invalidation and provider behavior was checked against the current
packages/coresource and the Astro 7.3.2 cache providers.AI assistance disclosure
Screenshots / test output
Not applicable (no UI change). The docs site builds locally with
pnpm --dir docs build, and no links point to the old/deployment/edge-cache/page.