Registry / storage / strapi-middleware-cache

strapi-middleware-cache

JSON →
library2.1.8jsnpmunverified

A cache middleware for Strapi v3 headless CMS that caches incoming GET requests and auto-busts on write operations. Current stable version is 2.1.8 (deprecated). Last updated 2021, no longer maintained. Requires Strapi 3.4.0+ and Node 14. Supports memory and Redis storage engines with per-model caching configuration. Deprecated in favor of strapi-plugin-rest-cache for Strapi v4. Key differentiator: simple LRU caching with automatic cache invalidation on PUT/PATCH/POST/DELETE.

npm install strapi-middleware-cache
INSTALL
IMPORT
SIG · STRAPI-MIDDLEWARE-
S
strapi-middleware-cache
storagejavascriptv2.1.8
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.

cache middleware
✓ module.exports = ({ env }) => ({ settings: { cache: { enabled: true } } });
✗ module.exports = { settings: { cache: { enabled: true } } };
Config must be a function receiving env in Strapi v3.
Model config
✓ models: ['article', 'product']
✗ models: ['Article', 'Product']
Model names must be lowercase, matching Strapi content type UIDs.
Redis storage
✓ model: { type: 'redis', redis: { hosts: ['127.0.0.1:6379'] } }
✗ model: { type: 'redis', host: '127.0.0.1', port: 6379 }
Redis config uses 'hosts' array, not single host/port.

Enable cache for 'review' model with Redis storage backend.

// config/middleware.js module.exports = ({ env }) => ({ settings: { cache: { enabled: true, models: ['review'], type: 'redis', redis: { hosts: [ { host: '127.0.0.1', port: 6379 } ] } } } });
Debug
Known issues
deprecatedProject is deprecated; switch to strapi-plugin-rest-cache.
fix
Use https://github.com/strapi-community/strapi-plugin-rest-cache
affects: <=2.1.8
breakingFull rewrite from v1 to v2; config may not be compatible.
fix
Re-read documentation and update config for v2 format.
affects: >=2.0.0 <2.0.1
gotchaModel names must be lowercase strings matching Strapi content type UIDs.
fix
Use e.g., 'article' not 'Article'.
affects: >=1.0.0
gotchaRedis hosts config requires array of objects with host and port.
fix
Use hosts: [{ host: '...', port: 6379 }]
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: Cannot read property 'cache' of undefined
Middleware config not wrapped in settings key or missing file.
fix
Ensure config/middleware.js exports function with settings.cache.
Error: No cache configuration found for model 'Article'
Model name case mismatch or not in models array.
fix
Use lowercase model UID in models array, e.g., 'article'.
Error: Redis configuration is invalid - hosts must be an array
Redis config uses single host/port instead of hosts array.
fix
Use hosts: [{ host: '127.0.0.1', port: 6379 }]
Upgrade
Version history
2.1.8latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
15
Resources
strapi-middleware-cache — npm install strapi-middleware-cache · libregistry