Express middleware to manage the Cache-Control header for HTTP caching. Version 1.2.0 is the latest stable release. It provides simple functions like `public()`, `private()`, `disable()`, `secure()`, and `custom()` to set caching directives. Key differentiators include support for ms-formatted TTL strings (e.g., '1d', '2h'), OWASP-recommended secure caching presets, and fine-grained control via an options object. Compared to other caching middleware like `helmet` or `express-cache-headers`, it focuses solely on Cache-Control and is lightweight. Requires Node >= 18.20.8.
npm install express-cache-ctrlNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates an Express app, disables caching for /api, sets public cache with 1-day TTL for /static, and starts the server.
Upgrade Node.js to 18.20.8 or later.
Always call the function: app.use('/api', cache.disable())Use valid ms format: numbers, '1s', '1m', '1h', '1d', '1w', '1y'. Avoid unsupported strings.
Replace `{ noCache: true }` with `cache.noCache()` or use `cache.disable()`.Use `const cache = require('express-cache-ctrl');` instead of `import cache from 'express-cache-ctrl';`Use a valid string like '1d', '2h', or a number in seconds.
Call the function: `app.use('/api', cache.disable())`