4.0.0
Fixes #98, #96, #75
Breaking changes
defineMultiCacheOptionscan be now imported fromnuxt-multi-cache/server-options- The location of
multiCache.serverOptions.tsis now being enforced as~~/server/multiCache.serverOptions.ts useDataCache,useRouteCacheanduseCDNHeadersrequire theH3Eventas the second argument in a nitro context. Previously, these were not working without an event when used for example in event handlers
New Features
bubbleError
New bubbleError option on every cache in the server options. If true, any error that occurs while interacting with the storage driver will be rethrown so it can be handled by your code. For example, when setting bubbleError: true for the data cache, useDataCache will throw an error if the call to storage.getItem() or storage.setItem() throws an error. In case of route cache, setting it to true will result in the entire page showing a nitro error if e.g. your cache backend is down.
useDataCacheCallback
A new composable and server util to cache the return value of a callback:
const { data } = await useAsyncData(() =>
useDataCacheCallback(
'current-time',
() => {
return {
value: Date.now().toString(),
maxAge: 600,
cacheTags: ['time'],
}
},
event,
),
)
This will call the callback only once, cache it and return the value of value. This is similar to useCachedAsyncData, but it can also be used in a Nitro context (event handlers, etc.).
Proper Types for API Routes
The module now generates proper types for its API purge/stats API endpoints.
Fixes
Usage with Nitro routeRules (e.g. swr)
If you prefer using Nitro's built in caching (such as swr [stale while revalidate]), you can now do so and use useDataCache and useCDNHeaders - they will work correctly for both the initial rendering and the subsequent "revalidate" rendering.
Usage of event.context
The module now adds anything state-related for the current request to event.context instead of event. This has previously been changed 3 times due to changing behaviour in Nitro.