Nuxt SSR Cache
raw JSON → 1.5.2 verified Sat Apr 25 auth: no javascript maintenance
nuxt-ssr-cache v1.5.2 is a cache middleware for Nuxt.js server-side rendering. It supports multiple cache stores: in-memory, Redis, Memcached, and layered multi-cache. The package allows prefixing cache keys by host, custom key functions, and version-based automatic cache purging on deployment. It is designed for Nuxt.js applications needing to reduce SSR load by caching rendered pages. The library has been stable since its last release but is not frequently updated. It relies on the Nuxt module system and optional peer dependencies for Redis and Memcached stores.
Common errors
error Error: Cannot find module 'cache-manager-redis' ↓
cause Missing optional dependency for Redis store.
fix
Install the Redis store package:
npm install cache-manager-redis error Error: The cache store configuration is invalid. Expected an object with a 'type' property. ↓
cause Using old string-based store configuration (e.g., `store: 'memory'`) after version 1.2.0.
fix
Change to object format:
store: { type: 'memory', max: 100, ttl: 60 } error Error: Invalid pages configuration. Pages must be an array of strings or RegExp. ↓
cause Passing a non-array or invalid element in the `pages` option.
fix
Ensure
pages is an array of strings (path prefixes) or RegExp objects. Warnings
gotcha The `key` option function, when provided, overrides both `useHostPrefix` and `pages`. Those properties are ignored. ↓
fix If you need to use `useHostPrefix` or `pages`, do not define the `key` function.
gotcha For multi-store (layered) cache, the `stores` array must contain configuration objects; using `type: 'multi'` alone without `stores` will cause an error. ↓
fix Ensure `stores` array is provided with at least one store configuration.
deprecated The package relies on `cache-manager-redis` and `cache-manager-memcached-store`, which are older libraries and may not be actively maintained. ↓
fix Consider using newer Redis/Memcached cache stores or evaluate alternative cache modules for Nuxt.
breaking In version 1.2.0, the `cache` config structure changed: `store` now expects an object with `type` instead of a string. Old configs with `store: 'memory'` will break. ↓
fix Update store configuration to object form: `store: { type: 'memory', ... }`.
Install
npm install nuxt-ssr-cache yarn add nuxt-ssr-cache pnpm add nuxt-ssr-cache Imports
- default wrong
import nuxtSsrCache from 'nuxt-ssr-cache' // Not a direct import; used as Nuxt modulecorrect// Add to modules in nuxt.config.js: 'nuxt-ssr-cache'
Quickstart
// nuxt.config.js
module.exports = {
version: '1.0.0',
modules: ['nuxt-ssr-cache'],
cache: {
useHostPrefix: false,
pages: ['/', '/about'],
store: {
type: 'memory',
max: 100,
ttl: 60
}
}
}