Skip to content

docs: add a Route Caching guide - #1820

Merged
swissky merged 13 commits into
emdash-cms:mainfrom
swissky:docs/edge-cache
Oct 16, 2026
Merged

swissky merged 13 commits into
emdash-cms:mainfrom
swissky:docs/edge-cache

Conversation

@swissky

@swissky swissky commented Jul 4, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Adds a deployment guide for caching rendered pages with Astro route caching, at /deployment/route-caching/. It covers:

  • choosing a cache provider (memoryCache() on Node.js, cacheCloudflare() on Cloudflare, with a link to Astro's other adapter providers)
  • routeRules and the query helpers' cacheHint, and the tag convention EmDash's built-in invalidation relies on
  • which writes invalidate which tags (entries, site chrome, redirect source paths), and what invalidates nothing
  • the responses that have to stay out of the cache (error responses, middleware redirects; preview links, 404s and signed-in renders are handled automatically)
  • how editors see cached pages, and why toolbar: "client" helps
  • the provider differences: per-process memory cache on Node and no invalidation for scheduled publishing there; on Cloudflare the response headers, default cache lifetimes, deploy cache key and Workers Cache purge rate limits

It also adds the page to the docs sidebar, updates the Workers Cache section in deployment/cloudflare.mdx (including the default lifetime a cache hint without maxAge gets), fixes the cross-links in object-cache.mdx and upgrade-to-v1.mdx, and clarifies in the toolbar reference 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

  • Bug fix
  • Feature (requires an accepted feature plan or RFC)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Your connection to this change

  • I use EmDash and ran into the problem this PR addresses
  • I maintain a tool, dependency, or service that EmDash uses, and this change concerns that integration
  • A Maintainer approved this specific change before I opened the PR

Checklist

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/core source and the Astro 7.3.2 cache providers.

AI assistance disclosure

  • This PR includes AI-generated code or text — model/tool: Claude Opus 5.5

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.

@changeset-bot

changeset-bot Bot commented Jul 4, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: aca0f63

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@github-actions github-actions Bot added review/needs-review No maintainer or bot review yet area/docs size/M labels Jul 4, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 4, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/admin@1820

@emdash-cms/auth

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/auth@1820

@emdash-cms/auth-atproto

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/auth-atproto@1820

@emdash-cms/blocks

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/blocks@1820

@emdash-cms/cloudflare

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/cloudflare@1820

@emdash-cms/contentful-to-portable-text

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/contentful-to-portable-text@1820

emdash

npm i https://pkg.pr.new/emdash-cms/emdash@1820

create-emdash

npm i https://pkg.pr.new/emdash-cms/emdash/create-emdash@1820

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/gutenberg-to-portable-text@1820

@emdash-cms/plugin-cli

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-cli@1820

@emdash-cms/plugin-test

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-test@1820

@emdash-cms/plugin-types

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-types@1820

@emdash-cms/registry-client

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/registry-client@1820

@emdash-cms/registry-lexicons

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/registry-lexicons@1820

@emdash-cms/registry-loader

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/registry-loader@1820

@emdash-cms/registry-moderation

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/registry-moderation@1820

@emdash-cms/registry-verification

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/registry-verification@1820

@emdash-cms/sandbox-workerd

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/sandbox-workerd@1820

@emdash-cms/x402

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/x402@1820

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-ai-moderation@1820

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-atproto@1820

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-audit-log@1820

@emdash-cms/plugin-color

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-color@1820

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-embeds@1820

@emdash-cms/plugin-field-kit

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-field-kit@1820

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-forms@1820

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-webhook-notifier@1820

commit: c56af45

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Suggested change
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 });

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Suggested change
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will be deprecating the emdash route cache provider.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood — the guide now recommends Astro's cacheCloudflare() only, with a one-line note that cloudflareCache() predates Astro route caching and is deprecated.

@github-actions github-actions Bot added review/awaiting-author Reviewed; waiting on the author to respond and removed review/needs-review No maintainer or bot review yet labels Jul 4, 2026

@ascorbic ascorbic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already built-in. It doesn't need a plugin

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are generally available now

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — caution removed, the guide no longer mentions beta.


```jsonc title="wrangler.jsonc"
{
"cache": { "enabled": true },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is added automatically if you enable the Cloudflare cache

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think preview links will always have a cookie set, which would disable caching

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions github-actions Bot added review/needs-rereview New commits since the last review and removed review/awaiting-author Reviewed; waiting on the author to respond labels Jul 5, 2026
@swissky

swissky commented Jul 5, 2026

Copy link
Copy Markdown
Member Author

Pushed a revision addressing the review:

  • Purge on publish is built-in — the plugin recipe is gone; the guide now documents the [collection, id] tag invalidation done by core's content API routes and the scheduled-publish sweep, and the tag convention route rules need to match it.
  • Beta caution removed — Workers Cache + tag purge are GA.
  • Manual wrangler step removed — the adapter writes cache.enabled into the generated Wrangler config when a cache provider is set.
  • cloudflareCache() — noted as deprecated in favor of Astro's cacheCloudflare().
  • Preview links — kept the opt-out and tightened the wording; I verified against a stock 0.27.0 install that preview responses do get stored in the Workers Cache despite private, no-store (details in the inline thread). Offered a small core follow-up (context.cache.set(false) in the preview/toolbar paths) if wanted.

Docs build is green locally.

@swissky
swissky force-pushed the docs/edge-cache branch from d9d883e to 9fc8b87 Compare July 6, 2026 19:12
@swissky swissky added the bot:review Trigger an emdashbot code review on this PR label Jul 10, 2026
@ascorbic ascorbic added bot:review Trigger an emdashbot code review on this PR and removed bot:review Trigger an emdashbot code review on this PR labels Jul 20, 2026
@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Jul 20, 2026
@swissky swissky added the bot:review Trigger an emdashbot code review on this PR label Jul 20, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.mdx page, plus the sidebar registration in docs/astro.config.mjs, the updated cross-links in object-cache.mdx and cloudflare.mdx.
  • The relevant runtime code: packages/core/src/astro/middleware/request-context.ts confirms preview and toolbar-injected responses are stamped Cache-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) confirm cache?.invalidate({ tags: [collection, id] }) is invoked after writes.
  • packages/cloudflare/src/worker.ts confirms the Cloudflare scheduled() handler passes onPublished to runScheduledTasks, so scheduled publishes do purge tags on Cloudflare deployments.
  • getEmDashEntry from packages/core/src/query.ts does return { entry, isPreview, cacheHint }, so the preview opt-out snippet is valid.
  • The docs package 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.

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Jul 20, 2026
@github-actions github-actions Bot added review/approved Approved; no new commits since needs-rebase and removed review/needs-rereview New commits since the last review labels Jul 20, 2026
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added the stale label Aug 4, 2026
@github-actions github-actions Bot removed the review/approved Approved; no new commits since label Sep 28, 2026
@swissky swissky added the bot:review Trigger an emdashbot code review on this PR label Sep 28, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in packages/core/src/cache/chrome-tags.ts, and the get*WithCacheHint helpers in menus/index.ts, settings/index.ts, taxonomies/index.ts, and widgets/index.ts expose those tags as cacheHint.
  • 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 from packages/cloudflare/src/worker.ts via invalidatePublishedTags().
  • Preview-token, _edit, and toolbar-injected responses are opted out of the route cache in packages/core/src/astro/middleware/request-context.ts; valid previews and toolbar-injected responses also get Cache-Control: private, no-store.
  • Admin/API responses use API_CACHE_HEADERS (private, no-store) from packages/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:141

    This 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 previous cache.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.
    

@emdashbot emdashbot Bot added review/approved Approved; no new commits since and removed bot:review Trigger an emdashbot code review on this PR review/needs-rereview New commits since the last review labels Sep 28, 2026
@github-actions github-actions Bot added review/needs-rereview New commits since the last review and removed review/approved Approved; no new commits since labels Sep 28, 2026
@swissky swissky added the bot:review Trigger an emdashbot code review on this PR label Sep 28, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in packages/cloudflare/src/worker.ts purges the same tags through invalidatePublishedTags().
  • Cache tags for chrome resources are exactly the documented emdash:* shape in packages/core/src/cache/chrome-tags.ts, and the write routes for site settings, menus, taxonomies (defs + terms + reorder), and widget areas all call cache.invalidate({ tags: [...] }) with those tags.
  • Preview-token, _edit, and toolbar-injected responses are opted out of the route cache in packages/core/src/astro/middleware/request-context.ts; valid previews and toolbar-injected responses also get Cache-Control: private, no-store.
  • Admin/API responses use API_CACHE_HEADERS (private, no-store) from packages/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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Suggested change
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.

@swissky

swissky commented Sep 29, 2026

Copy link
Copy Markdown
Member Author

Thanks, both done: the Edge Caching guide now notes that the pre-1.0 cloudflareCache() provider was removed and links to the upgrade guide, and the upgrade guide now points to the built-in tag purge on the Edge Caching page instead of a manual cache.purge() call.

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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].ts invalidates [collection, resolvedId] on PUT/DELETE; publish.ts, unpublish.ts, restore.ts, schedule.ts, unschedule.ts, discard-draft.ts, and permanent.ts all do the same. index.ts (create) and duplicate.ts invalidate [collection].
  • Scheduled publishing: packages/cloudflare/src/worker.ts passes invalidatePublishedTags to runScheduledTasks, which purges [collection, id] for items promoted by the cron sweep.
  • Chrome tags: packages/core/src/cache/chrome-tags.ts emits emdash:settings, emdash:menu:{name}, emdash:taxonomy:{name}, and emdash:widget-area:{name}. The settings, menu, taxonomy, and widget-area write routes all call cache.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.ts opts ?_preview=, ?_edit, and toolbar-injected responses out of the route cache and sets Cache-Control: private, no-store for valid previews and toolbar responses. packages/core/src/api/error.ts sets API_CACHE_HEADERS to private, no-store for API responses.
  • Sidebar/cross-links: the new page is registered after Object Cache, object-cache.mdx now links to it, cloudflare.mdx links to it, and upgrade-to-v1.mdx points 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Suggested change
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:

Suggested change
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/)).

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ts shouldBypass() includes routeCacheFill === true).
  • Astro.cache?.enabled guard: present in both the entry example and the 404 example in edge-cache.mdx.
  • All four chrome cache-hint helpers named: getMenuWithCacheHint, getSiteSettingsWithCacheHint, getTaxonomyTermsWithCacheHint, and getWidgetAreaWithCacheHint are all documented and exported from emdash.
  • Legacy cloudflareCache() provider: documented as removed with a link to the upgrade guide. The @emdash-cms/cloudflare package 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.ts passes invalidatePublishedTags to runScheduledTasks, 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 get Cache-Control: private, no-store. API responses carry the same header via API_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 danielmlr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) yields Cloudflare-CDN-Cache-Control: public, not no-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 routeRules example caches /sitemap.xml but not the per-collection /sitemap-[collection].xml files.
  • 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 the no-store claim here, and item 2 (editors get the cached variant) should mention toolbar: "client".
  • The PR description still describes purging through content:afterSave/content:afterDelete hooks 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).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?_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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@danielmlr danielmlr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants