Release Notes
Major Changes
Minor Changes
#16335
9a53f77Thanks @ascorbic! - Adds an opt-in CDN cache provider for Astro route caching on Cloudflare Workers[!WARNING] This provider requires the Cloudflare Workers Cache feature, which is currently in private beta. It is opt-in: nothing changes unless you import
cacheCloudflare()and set it as your provider. But without beta access it does not work and should not be used. Cloudflare Workers run in front of the cache, so cached responses are never served, and callingcache.invalidate()throws an error.Setup
Import
cacheCloudflare()from@astrojs/cloudflare/cacheand set it as your cache provider:import { defineConfig } from 'astro/config'; import cloudflare from '@astrojs/cloudflare'; import { cacheCloudflare } from '@astrojs/cloudflare/cache'; export default defineConfig({ adapter: cloudflare(), cache: { provider: cacheCloudflare(), }, });The adapter automatically enables the Worker caching layer when a Cloudflare cache provider is configured. No manual wrangler.jsonc changes are needed.
Caching responses
Use
Astro.cache.set()in your pages and API routes to cache responses. The provider setsCloudflare-CDN-Cache-ControlandCache-Tagheaders, which are read by Cloudflare's built-in caching layer. Cache hits bypass Worker execution entirely, meaning your Worker is not invoked for cached responses.--- Astro.cache.set({ maxAge: 300, tags: ['products'] }); const data = await fetchProducts(); --- <ProductList items={data} />You can also set cache rules for groups of routes in your config:
cache: { provider: cacheCloudflare() }, routeRules: { '/products/[...slug]': { maxAge: 3600, tags: ['products'] }, '/api/[...path]': { maxAge: 60, swr: 600 }, },Invalidation
Purge cached responses by tag or path from any API route or server endpoint:
// src/pages/api/purge.ts export async function POST({ request, cache }) { await cache.invalidate({ tags: ['products'] }); return new Response('Purged'); } // Path-based invalidation (implemented via an auto-generated path tag) await cache.invalidate({ path: '/products/123' });Both tag-based and path-based invalidation are supported.
Patch Changes
#16961
96398e8Thanks @adamchal! - Speeds upastro syncby no longer starting the Cloudflare runtime during type generation#16671
fd926fdThanks @alexanderniebuhr! - Removes deprecations warnings added in Astro v6 for Cloudflare specific Astro.locals properties.#17027
241250bThanks @ocavue! - Triggers beta prereleases for packages that are still on alphaUpdated dependencies []:
- @astrojs/[email protected]