Registry / cache / nuxt-perfect-cache

nuxt-perfect-cache

JSON →
library1.1.4jsnpmunverified

A Nuxt.js module for server-side page and API response caching using Redis. Current stable version is 1.1.4. It provides easy-to-configure Redis-backed caching of full rendered pages and API requests with per-route expiration. Key differentiators: simple module-based setup, injects $cacheFetch, $cacheRead, $cacheWrite methods, supports separate Redis server per route, and can ignore connection errors for resilience. Works with Nuxt 2 (SSR).

npm install nuxt-perfect-cache
INSTALL
IMPORT
SIG · NUXT-PERFECT-CACHE
N
nuxt-perfect-cache
cachejavascriptv1.1.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

nuxt-perfect-cache module
// nuxt.config.js modules: ['nuxt-perfect-cache', options]
import NuxtPerfectCache from 'nuxt-perfect-cache'
This is a Nuxt module, not a standard import; configured in nuxt.config.js under modules array.
$cacheFetch
// in asyncData or server-side: const data = await ctx.$cacheFetch({ key: 'myKey', expire: 120 }, () => fetch('...'))
import { $cacheFetch } from 'nuxt-perfect-cache'
$cacheFetch is injected as a plugin; available on context or this (in Nuxt 2). Not directly importable.
$cacheRead and $cacheWrite
// server-side only: const data = await ctx.$cacheRead({ key: 'myKey' }) await ctx.$cacheWrite({ key: 'myKey', expire: 3600 }, 'content')
import { $cacheRead } from 'nuxt-perfect-cache'
Methods are injected and only work on the server (during SSR). Do not use on client side.

Configures redis caching for the homepage and demonstrates API response caching with $cacheFetch.

// nuxt.config.js module.exports = { modules: [ [ 'nuxt-perfect-cache', { disable: false, appendHost: true, ignoreConnectionErrors: false, prefix: 'r-', url: 'redis://127.0.0.1:6379', getCacheData(route, context) { if (route !== '/') { return false } return { key: 'my-home-page', expire: 60 * 60 } } } ] ], publicRuntimeConfig: { nuxtPerfectCache: { disable: process.env.NUXT_PERFECT_CACHE_DISABLED } } } // In a page component: export default { async asyncData(ctx) { const data = await ctx.$cacheFetch({ key: 'todos', expire: 120 }, () => { return ctx.$axios.$get('https://jsonplaceholder.typicode.com/todos/1') }) return { data } } }
Debug
Known issues
breakingdisable option defaults to true; module will not cache unless you explicitly set disable: false
fix
Set disable: false in module options or set NUXT_PERFECT_CACHE_DISABLED=0 in .env
affects: >=1.0.0
gotchaCached pages expose server-rendered data to all users; do not cache user-specific content
fix
Ensure getCacheData returns false for routes with personalized data
affects: >=1.0.0
gotchaRedis credentials (password) may be bundled in client-side code if url contains password
fix
Use a private Redis server or avoid password in url; the url is injected into client bundle
affects: >=1.0.0
deprecatedignoreConnectionErrors option added in v1.0.4; if you use older versions this option is ignored
fix
Upgrade to >=1.0.4 to use this option
affects: <1.0.4
Errors
Common errors & fixes
Nuxt build hangs or page keeps re-rendering
Module changes Nuxt render function; during development, non-cached routes may loop
fix
Open a route that is not cached (getCacheData returns false) until build process completes
Cannot read properties of null (reading 'getCacheData')
getCacheData is required but may be missing or undefined in module options
fix
Ensure getCacheData function is defined in the module options array
TypeError: ctx.$cacheFetch is not a function
Attempting to use $cacheFetch on client side or before plugin registration
fix
Use $cacheFetch only inside asyncData, fetch, or serverMiddleware; ensure module is correctly loaded
Upgrade
Version history
1.1.4latest on npm
Audit
Dependencies
ioredisrequiredRedis client for cache storage
Agent activity
41 hits · last 30 days
node
36
Resources
nuxt-perfect-cache — npm install nuxt-perfect-cache · libregistry