An Express middleware for setting response cache headers. Version 0.1.4 is the latest stable release. It allows you to control cache behavior per-route by providing options such as TTL (time-to-live), nocache, private, and mustrevalidate. Unlike more complex caching solutions like apicache or express-cache-ctrl, this package focuses solely on setting cache HTTP headers (Cache-Control, Pragma, Expires) with minimal configuration. It is lightweight and does not require a store, making it ideal for simple caching scenarios where only headers are needed.
npm install express-cache-headersVerified import paths — ran on the pinned version, not inferred.
Demonstrates global and per-route use of cache middleware with ttl, nocache, and private options.
Do not use both global and per-route cache middleware simultaneously; choose one pattern.
If actual response caching is needed, use a package like apicache or express-cache-ctrl instead.
Review if you need HTTP/1.0 compatibility; if not, consider manually setting Cache-Control headers.
Replace `import cache from 'express-cache-headers'` with `const cache = require('express-cache-headers');`Pass a number or options object: `app.use(cache(10));` or `app.use(cache({ttl: 10}));`Set custom Cache-Control headers before the cache middleware or avoid overriding them.