Middleware for Express/Connect to set HTTP cache headers (Cache-Control, Expires) on responses. Version 1.0.0 (latest) requires Node >=6. Methods: res.cacheFor(milliseconds) or res.cacheFor(amount, unit) using Moment.js duration syntax. Can also set default cache duration for all routes in a middleware stack. Lightweight, no dependencies beyond Node built-ins. Differs from express-cache-headers by offering both per-response and global configuration.
npm install cacheable-middlewareVerified import paths — ran on the pinned version, not inferred.
Demonstrates two usage patterns: global cache duration applied to a path and per-response control via res.cacheFor().
Upgrade Node.js to version 6 or higher.
Consider using express.static with maxAge option for static files: app.use('/static', express.static('public', { maxAge: '1d' })).Use valid Moment.js duration formats: number (milliseconds) or number + string (e.g., 6, 'months', 3, 'hours').
Call res.cacheFor() at the beginning of the route handler, before sending response.
Use default import: const cacheable = require('cacheable-middleware');Run npm install cacheable-middleware and verify package.json.
Ensure app.use(cacheable()) is called before defining routes that use res.cacheFor().
No dependency data recorded yet.