Registry / web-framework / express-cache-controller

express-cache-controller

JSON →
library1.1.0jsnpmunverified

express-cache-controller is an Express.js middleware designed to simplify the management of Cache-Control HTTP headers for client-side caching. It offers a straightforward API to configure directives such as `max-age`, `no-cache`, `no-store`, `public`, and `private` globally for an application or on a per-route basis via `res.cacheControl`. The package is lightweight and focuses solely on setting response headers to guide browser and proxy caching behavior. The current stable and only version, 1.1.0, was last published in October 2017, indicating it is effectively an abandoned project with no ongoing development or official support. Users integrating this package into modern Node.js environments should be aware of its CommonJS-only nature and the absence of recent security patches or feature enhancements compared to more actively maintained caching solutions.

npm install express-cache-controller
INSTALL
IMPORT
SIG · EXPRESS-CACHE-CONT
E
express-cache-controller
web-frameworkjavascriptv1.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

cacheControl
const cacheControl = require('express-cache-controller');
import cacheControl from 'express-cache-controller';
This package is CommonJS-only (published 2017). ESM import syntax will fail without a transpiler or CommonJS wrapper.
cacheControl
app.use(cacheControl({ maxAge: 3600 }));
app.use(require('express-cache-controller')());
While functional, storing the middleware in a variable `cacheControl` is clearer for subsequent usage and configuration.
res.cacheControl
res.cacheControl = { maxAge: 30, public: true };
After the middleware `cacheControl()` is loaded, the `res.cacheControl` property becomes available to override default settings on a per-request basis.

This quickstart demonstrates setting global `Cache-Control` defaults, overriding them per-route, disabling caching, and applying specific cache settings to error responses.

const express = require('express'); const cacheControl = require('express-cache-controller'); const app = express(); const PORT = process.env.PORT || 3000; // Apply cache control middleware with a default maxAge of 60 seconds app.use(cacheControl({ maxAge: 60 })); // Route with default caching (max-age=60) app.get('/', (req, res) => { res.send('This page will be cached for 60 seconds.'); }); // Route overriding the default cache control to be shorter (30 seconds) app.get('/short-cache', (req, res) => { res.cacheControl = { maxAge: 30 }; res.send('This page will be cached for 30 seconds.'); }); // Route setting no-cache app.get('/no-cache', (req, res) => { res.cacheControl = { noCache: true }; res.send('This page will not be cached.'); }); // Error handling middleware with specific cache control app.get('/error', (req, res, next) => { next(new Error('Something went wrong!')); }); app.use((err, req, res, next) => { // Set very short cache for error responses res.cacheControl = { maxAge: 5, noStore: true }; res.status(500).send(`Error: ${err.message}. This error response caches for 5 seconds.`); }); app.listen(PORT, () => { console.log(`Server running on http://localhost:${PORT}`); console.log('Try visiting / and then /short-cache and /no-cache'); });
Debug
Known issues
breakingThe package is CommonJS-only. Attempting to use `import` syntax in an ESM module without proper transpilation or configuration will result in errors.
fix
Ensure your project uses CommonJS (`require`) for importing `express-cache-controller` or configure your build system to handle CommonJS modules in an ESM context.
affects: >=1.0.0
gotchaThis package is effectively abandoned. It has not been updated since October 2017 (v1.1.0), meaning there will be no further bug fixes, security patches, or feature enhancements.
fix
For new projects or applications requiring ongoing support and security, consider more actively maintained Express caching solutions or implementing `Cache-Control` headers manually.
affects: >=1.0.0
gotchaUsing this middleware does not implement server-side caching. It only sets the `Cache-Control` HTTP response header, instructing clients (browsers, proxies) on how to cache content. It will not reduce server load from actual request processing.
fix
If server-side caching is required to reduce backend load or improve response times by serving pre-computed results, integrate a separate server-side caching solution (e.g., Redis, `node-cache`, `express-response-cache`).
affects: >=1.0.0
gotchaIncorrect middleware order can lead to `Cache-Control` headers being overridden by other middleware or explicit `res.set()` calls later in the request-response cycle.
fix
Place `express-cache-controller` middleware early in your Express application's middleware stack. If specific routes need different headers, set `res.cacheControl` *after* this middleware has run, but before `res.send()` or `res.end()`.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: require(...) is not a function
Attempting to call the result of `require('express-cache-controller')` as a function directly, when it's already the middleware function itself.
fix
Correct usage is `const cacheControl = require('express-cache-controller'); app.use(cacheControl(options));`
Cache-Control header is missing or incorrect in response.
The `express-cache-controller` middleware was not applied, or `res.cacheControl` was set incorrectly/too late, or another middleware overwrote the header.
fix
Ensure `app.use(cacheControl())` is called early in your Express app. Verify `res.cacheControl = { ... }` is used correctly for overrides. Inspect network requests to confirm the header is being sent as expected and debug for conflicting middleware.
ReferenceError: cacheControl is not defined
Attempting to use `cacheControl` in an ESM module context without a CommonJS `require` statement.
fix
This package is CommonJS. Use `const cacheControl = require('express-cache-controller');` at the top of your file. If you must use ESM, consider wrapping it or finding a more modern alternative.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
Amazon
1
OpenAI (training)
1
Resources
express-cache-controller — npm install express-cache-controller · libregistry