{"id":17606,"library":"express-cache-controller","title":"Express Cache Controller Middleware","description":"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.","status":"abandoned","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/DaMouse404/express-cache-controller","tags":["javascript","express","max-age","maxage","cache","cache-control","no-cache"],"install":[{"cmd":"npm install express-cache-controller","lang":"bash","label":"npm"},{"cmd":"yarn add express-cache-controller","lang":"bash","label":"yarn"},{"cmd":"pnpm add express-cache-controller","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only (published 2017). ESM import syntax will fail without a transpiler or CommonJS wrapper.","wrong":"import cacheControl from 'express-cache-controller';","symbol":"cacheControl","correct":"const cacheControl = require('express-cache-controller');"},{"note":"While functional, storing the middleware in a variable `cacheControl` is clearer for subsequent usage and configuration.","wrong":"app.use(require('express-cache-controller')());","symbol":"cacheControl","correct":"app.use(cacheControl({ maxAge: 3600 }));"},{"note":"After the middleware `cacheControl()` is loaded, the `res.cacheControl` property becomes available to override default settings on a per-request basis.","symbol":"res.cacheControl","correct":"res.cacheControl = { maxAge: 30, public: true };"}],"quickstart":{"code":"const express = require('express');\nconst cacheControl = require('express-cache-controller');\n\nconst app = express();\nconst PORT = process.env.PORT || 3000;\n\n// Apply cache control middleware with a default maxAge of 60 seconds\napp.use(cacheControl({ maxAge: 60 }));\n\n// Route with default caching (max-age=60)\napp.get('/', (req, res) => {\n  res.send('This page will be cached for 60 seconds.');\n});\n\n// Route overriding the default cache control to be shorter (30 seconds)\napp.get('/short-cache', (req, res) => {\n  res.cacheControl = {\n    maxAge: 30\n  };\n  res.send('This page will be cached for 30 seconds.');\n});\n\n// Route setting no-cache\napp.get('/no-cache', (req, res) => {\n  res.cacheControl = {\n    noCache: true\n  };\n  res.send('This page will not be cached.');\n});\n\n// Error handling middleware with specific cache control\napp.get('/error', (req, res, next) => {\n  next(new Error('Something went wrong!'));\n});\n\napp.use((err, req, res, next) => {\n  // Set very short cache for error responses\n  res.cacheControl = {\n    maxAge: 5,\n    noStore: true\n  };\n  res.status(500).send(`Error: ${err.message}. This error response caches for 5 seconds.`);\n});\n\napp.listen(PORT, () => {\n  console.log(`Server running on http://localhost:${PORT}`);\n  console.log('Try visiting / and then /short-cache and /no-cache');\n});","lang":"javascript","description":"This quickstart demonstrates setting global `Cache-Control` defaults, overriding them per-route, disabling caching, and applying specific cache settings to error responses."},"warnings":[{"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.","message":"The package is CommonJS-only. Attempting to use `import` syntax in an ESM module without proper transpilation or configuration will result in errors.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"For new projects or applications requiring ongoing support and security, consider more actively maintained Express caching solutions or implementing `Cache-Control` headers manually.","message":"This 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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`).","message":"Using 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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()`.","message":"Incorrect middleware order can lead to `Cache-Control` headers being overridden by other middleware or explicit `res.set()` calls later in the request-response cycle.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Correct usage is `const cacheControl = require('express-cache-controller'); app.use(cacheControl(options));`","cause":"Attempting to call the result of `require('express-cache-controller')` as a function directly, when it's already the middleware function itself.","error":"TypeError: require(...) is not a function"},{"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.","cause":"The `express-cache-controller` middleware was not applied, or `res.cacheControl` was set incorrectly/too late, or another middleware overwrote the header.","error":"Cache-Control header is missing or incorrect in response."},{"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.","cause":"Attempting to use `cacheControl` in an ESM module context without a CommonJS `require` statement.","error":"ReferenceError: cacheControl is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}