Repository navigation
Most changes in 5.0 fix caching bugs: they change what is cached and for how long, and neither the build nor the type checker notices them. This release also hardens the module against cache poisoning and adds a Cache-Status header, agent skills and Cloudflare Workers support.
Upgrade with your coding agent
The package now ships two agent skills for coding agents such as Claude Code, Cursor or Codex:
nuxt-multi-cache-upgrade-v5checks every breaking and behavior change below against your project and reports each one with evidence.nuxt-multi-cachehelps with adding, reviewing and debugging caching.
Install 5.0 first, then link the skills into your agent's skill folder:
# pnpm 12.11+
pnpm approve
# npm, yarn, bun
npm install -D skills-npm && npx skills-npm setup
# or from the repository
npx skills add dulnan/nuxt-multi-cacheOr just symlink from node_modules/nuxt-multi-cache/skills/*.
Then ask your agent:
Upgrade nuxt-multi-cache to 5.0 and check every breaking change against this project. Report each one as affected or not affected.
The skill fixes what is mechanical and lists everything else for you to decide, including what it can't check in the repository, such as environment variables of the deployment.
Requirements
- Nuxt
^4.0.0. On Nuxt 3, the module isn't loaded and Nuxt logs a warning. - Node
^20.19.0 || >=22.12.0, required by@nuxt/kit4.6 and unplugin 3. - The module's runtime dependencies (
@nuxt/kit,h3,unstorage,consola, …) are now declared, so strict installs (pnpm without hoisting) work.
New features
- Cache-Status header (RFC 9211) for the route cache with
route.cacheStatus, e.g.nuxt-multi-cache; hit; ttl=376. It can be turned on at runtime withNUXT_MULTI_CACHE_ROUTE_CACHE_STATUS. (#102) - CDN helper:
addCustomDirective()(#123, thanks @lukereative),getControl()with the newCDNCacheControltype, andmust-understand. - Server options in Nuxt layers. (#124)
- Cloudflare Workers work and are tested in CI with Miniflare. (#104)
- Agent skills (see above).
Breaking changes
- A max age of
0means "never" in the data cache.addToCache(value, tags, 0),helper.setMaxAge(0)inuseDataCacheCallbackandserverMaxAge: 0used to store the item permanently. Use'permanent'(or-1) for that. useCachedAsyncDatawithoutserverMaxAgedoesn't cache on the server. It cached permanently. Items that 4.x stored for it are no longer read.- Uncacheable items bubble. With
bubbleCacheability, a component or data cache item marked as uncacheable makes the route uncacheable and the CDN headermax-age=0, no-store.useDataCacheCallbackno longer stores a result aftersetUncacheable(). - A
<RenderCacheable>child with slot content needs acache-key, because the generated key only contains the props. This includes<NuxtLink>text</NuxtLink>,<Transition>, named slots and a nested<RenderCacheable>. Lazy components (<LazyFoo>) need one too: they all had the same name, so two of them could render each other's markup. - A
cacheKeyPrefixmethod that returns no prefix gets the prefix{none}. Before, such a request's key could address the items of another prefix. Existing items of these requests are missed once, and purging them by key needs{none}--<key>. - Permanent items get no storage TTL. Redis, Upstash and Vercel KV rejected the old
ttl: -1, so permanent route and component items were never stored; Cloudflare KV expired them after 60 s. Now they stay until purged. The TTL lasts until the later of the max age and the stale-if-error expiry, and stale-while-revalidate routes get no TTL. - A set API token is required, even with authorization disabled. A build with
authorization: falseand a token from runtime config had an open API. To disable authorization at runtime, also setNUXT_MULTI_CACHE_API_AUTHORIZATION_TOKEN=(empty). - Types:
useMultiCacheApp()returnsMultiCacheApp | undefined(andNitroApp.multiCacheis optional);DataCacheItem.dataisunknown;state.keysBeingRevalidatedis aMap;CacheabilityInterfacehas a newgetCacheable()method; the CDN helper uses@tusbar/cache-control3.x.
Behavior changes
Max age and the data cache
- Negative max ages other than
-1, andNaN, mean "never" (they meant "permanent").Infinitymeans "permanent" (it was never served). 'permanent'no longer raises a lower max age set before.- A bubbled item without stale-if-error keeps the page's stale-if-error.
clientMaxAgeofuseCachedAsyncDataaccepts every max age, such as'5m'and'permanent'. An invalid string now throws on the client too.- Falsy cached values (
0,false,'',null) are cache hits inuseDataCacheCallbackanduseCachedAsyncData. - The data cache stores items with max age
0and stale-if-error, sostaleValueworks for them. - With
bubbleCacheability, the values passed toaddToCache()bubble even if the data cache doesn't store the item: disabled at runtime,enabledForRequestfalse, a key with?, a failed read. Pages then get the data's max age and tags.
Component cache
- A wrapper that forwards its slot into
<RenderCacheable>is cached if it sets acache-key, and so is av-foror a multi-root<template>as the first node. Don't wrap a layout's page<slot />this way: it caches whole pages without their head tags and payload. - Nested
<RenderCacheable>instances merge into the outer one: an innerno-cacheor uncacheable instance makes the outer one uncacheable, and the inner max age and tags apply to the outer item. - Each cached component stores the modules of its own render, so a cache hit renders the right styles and preload links.
- Generated keys escape quotes and backslashes in prop values and
:,,and\in object keys. Keys of props without them are unchanged. - Keys with a
?are neither read nor stored.
Route cache
- Only
GETandHEADrequests are served from and stored in the route cache. API routes requested with other methods during SSR still pass their route cache values to the page throughuseCacheAwareFetchInterceptor. - The module API, Nuxt's build assets and the error page never use the route cache. Paths below
api.prefixare always excluded. - Static files and paths excluded by
route.appliesskip the route cache entirely, also the lookup. The default static file check ignores the query string, andappliesgets the decoded path. - Requests with an ambiguous path (
//contact, a backslash, a.or..segment, an encoded?) don't use the route cache. - Route keys with a
?(frombuildCacheKey) are neither read nor stored. - The root path is stored as
{root}(with unstorage 1.17.6, it wasn't cached at all). - An
enabledForRequestthat throws no longer fails the request: the page is rendered without the route cache. - Internal headers of API routes are no longer stored with the route.
- A stale-while-revalidate revalidation counts for 60 seconds at most, and a stale route is no longer served after a revalidation that wasn't stored.
Stale if error
- A stale route is only served for server errors (5xx and unhandled errors), not for a 404.
- A route with a permanent stale-if-error is served stale.
- Stale routes are served from a Nitro error handler: browsers get the cached status code (it was the error status), the default status text, and the headers of a cache hit. Cookies and headers set by the failed request are no longer sent along. The app's error handler isn't called for them; Nitro's
errorhook still is. - Errors that don't end the request (
event.captureError) no longer serve the stale route. - Pages with
experimental.inlineErrorRenderingare served stale too.
Fetch interceptor
- Internal requests are marked with a random token instead of
true, and only for relative URLs. Requests to absolute URLs no longer bubble route cache values (their CDN headers still merge). The header is removed from the request once recognized, so aproxyroute rule can't forward the token. - The page gets the route cache max age, stale-if-error and uncacheability of the API routes it fetches, not only their tags.
- No empty cache tag from API routes without route cache tags, and the tags of a retried request are kept.
CDN headers
Cache-Controlgetsprivatewhen the CDN header isprivateorno-store, because Fastly ignores both inSurrogate-Control. Turn it off withcdn.privateCacheControl: false.s-maxageis capped by all sources: merged responses, bubbled items and the page's own max age. A bubbled "uncacheable" addsno-store.'permanent'no longer writesmax-age=-1, andNaNwritesmax-age=0.- Merged headers are parsed with
@tusbar/cache-control3.x: aprivate="Set-Cookie"from an API route makes the page private. NUXT_MULTI_CACHE_CDN=falseturns off the CDN headers. Before, only the interceptor read it.
API and runtime config
NUXT_MULTI_CACHE_API_ENABLED=falsedisables the API endpoints (404). It was ignored.- Runtime config can enable a feature that has
enabled: false: a feature is added to the build when its key exists in the module options. The startup table says "Added in Build" and has an API row. cacheTagInvalidationDelay: 0purges during the request (it became 60000).cacheTagInvalidator.add()returns a promise. On Cloudflare presets the delay is always 0, because Workers don't run timers after the response.- API responses are sent with
Cache-Control: private, no-store, a private CDN header,X-Content-Type-Options: nosniffand a sandbox CSP. The inspect endpoint sends route and component items astext/plain. - A
multiCache.serverOptions.tsin a Nuxt layer is used if the app has none.
Logging
- The module's server logs appear. In 4.x its runtime logger printed nothing, so storage and purge errors were silent. With
debug: true, every cache operation is logged.
Security
5.0 closes several ways to get content cached for the wrong request
- Cache poisoning through paths that the router and the cache key read differently (
//contact, dot segments, encoded?), through keys cut off at?, through crafted props of components with generated keys, and through the prefix of acacheKeyPrefixmethod. - Authorized API responses could be route cached or CDN cached and served to anyone, and inspected markup ran in the browser. Because the module doesn't cache anything by default, you would have to marked this response as cacheable, for example through a server middleware (which you really shouldn't)
- Any client could request the internal cache headers of API routes (e.g. cache tags)
- When a failed request returned a stale route, it would send a
set-cookieheader from the failed request - A build with
authorization: falseand a runtime token had an open API. You now have to explicitly set an empty token as well.
After upgrading
Purge all caches after deploying (POST /__nuxt_multi_cache/purge/all, or the configured api.prefix) if you use a persistent storage such as Redis. Items stored by 4.x keep working, but keys changed, and some items have a wrong expiry, the internal headers of API routes, the modules of other components or request-specific nested markup.
The upgrade skill has the details and the checks for each change.