Registry / database / strapi-cache

strapi-cache

JSON →
library1.11.0jsnpmunverified

An LRU-Cache plugin for Strapi v5 that boosts API performance by caching REST and GraphQL responses. Current version 1.11.0, active development. Supports in-memory, Redis, and Valkey providers, with configurable TTL, max size, route exclusion, header caching, and custom key generation. Lightweight with zero overhead, integrates via Strapi's config/plugins file. Release cadence is frequent (multiple updates per month). Differentiator: dedicated Strapi v5 plugin with both REST and GraphQL caching, LRU strategy, and multiple storage backends.

npm install strapi-cache
INSTALL
IMPORT
SIG · STRAPI-CACHE
S
strapi-cache
databasejavascriptv1.11.0
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.

strapi-cache plugin registration
✓ // config/plugins.js or .ts module.exports = { 'strapi-cache': { enabled: true, config: { provider: 'memory', max: 1000, ttl: 3600000 } } }
✗ const strapiCache = require('strapi-cache');
This is a Strapi plugin, not a regular module. Configure via Strapi's config/plugins.js or config/plugins.ts. Do not import or require it directly in your code.
env() usage
✓ import '@strapi/strapi'; // env is provided globally in Strapi config files // config/plugins.ts 'strapi-cache': { enabled: true, config: { redisConfig: env('REDIS_URL') } }
✗ const { env } = require('@strapi/strapi');
In Strapi v5, the `env` function is a global available in config files (e.g., config/plugins.ts, config/database.ts) without separate import. Only import if you need it outside config.
TypeScript config plugins
✓ // config/plugins.ts export default { 'strapi-cache': { enabled: true, config: { provider: 'redis', redisConfig: 'redis://localhost:6379' } } }
✗ import strapiCache from 'strapi-cache'; // wrong: direct import
Strapi plugins are configured via the `config/plugins.{js,ts}` file. Use `export default` for TypeScript, `module.exports` for JavaScript. Do not import the plugin package directly.

Strapi v5 plugin configuration with in-memory cache: 500 items max, 30 min TTL, 100 MB size, caches /api/products and /api/categories but excludes /api/products/private, caches headers but not access-control-allow-origin.

// config/plugins.js module.exports = { 'strapi-cache': { enabled: true, config: { provider: 'memory', max: 500, ttl: 1000 * 60 * 30, size: 1024 * 1024 * 100, cacheableRoutes: ['/api/products', '/api/categories'], excludeRoutes: ['/api/products/private'], cacheHeaders: true, cacheHeadersDenyList: ['access-control-allow-origin'], cacheAuthorizedRequests: false } } };
Debug
Known issues
breakingThis plugin is designed exclusively for Strapi v5. Using it with older versions (v4 or below) will cause initialization failures.
fix
Ensure your project runs Strapi v5.
affects: >=1.0.0
gotchaThe `cacheableRoutes` config caches routes that START with the provided paths, not exact matches. E.g., '/api/products' will also cache '/api/products/featured'. Use regular expressions or exact matching if needed.
fix
If you need exact route matching, implement a custom keyGenerator or check the plugin source for more control.
affects: >=1.0.0
breakingWhen `provider` is set to 'redis' or 'valkey', `redisConfig` is REQUIRED. Missing it will cause connection errors.
fix
Provide a valid Redis/Valkey URL or config object in `redisConfig`.
affects: >=1.0.0
gotchaThe `excludeRoutes` takes precedence over `cacheableRoutes`. If a route matches both lists, it will be excluded.
fix
Order your lists accordingly; exclusions are evaluated after cacheable routes.
affects: >=1.0.0
deprecatedSupport for Valkey is experimental and may change in future versions.
fix
Monitor release notes for final Valkey support. Prefer Redis for production.
affects: >=1.0.0 <2.0.0
Errors
Common errors & fixes
Error: Cannot find module 'strapi-cache'
The package is not installed or not in node_modules.
fix
Run `npm install strapi-cache` in your project root.
TypeError: env is not a function
Using `env` outside of Strapi config files where it is globally available.
fix
Use `env` only inside config/plugins.{js,ts} or config/database.{js,ts} without importing. If needed elsewhere, import from '@strapi/strapi': `import { env } from '@strapi/strapi';`
Error: provider is required when using redis config
Setting `redisConfig` without explicitly setting `provider: 'redis'` (or 'valkey').
fix
Set `provider: 'redis'` (or 'valkey') in the config object.
Error: listen EADDRINUSE :::1337
Another process is already using the default Strapi port (1337). Not directly related to strapi-cache but common in fresh installations.
fix
Stop other Strapi instances or change the port in config/server.js via `yarn develop --port 1338`.
Upgrade
Version history
1.11.0latest on npm
Audit
Dependencies
@strapi/sdk-pluginrequiredRequired to build as a Strapi plugin
@strapi/strapirequiredCore Strapi runtime
reactoptionalUsed by Strapi admin panel (plugin depends on it for admin UI if any)
react-domoptionalReact DOM for admin panel
react-router-domoptionalRouting for admin panel
styled-componentsoptionalCSS-in-JS for admin panel components
Agent activity
19 hits · last 30 days
node
16
OpenAI (training)
1
Resources
strapi-cache — npm install strapi-cache · libregistry