Registry / devops / express-cache-controlfreak

express-cache-controlfreak

JSON →
library0.1.2jsnpmunverified

Express middleware (v0.1.2, low activity) that adds a chainable `cacheControl` method to response objects for setting Cache-Control headers. Supports string patterns (public, private, no-cache, no-store), time strings for max-age (e.g. '1h'), and explicit option objects. Requires peer dependency express >=4.0.0. Unlike similar libraries like `express-cache-control`, it does not automatically set legacy Expires headers. Used by few projects; no recent updates.

npm install express-cache-controlfreak
INSTALL
IMPORT
SIG · EXPRESS-CACHE-CONT
E
express-cache-controlfreak
devopsjavascriptv0.1.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

cacheControl
import cacheControl from 'express-cache-controlfreak'
const cacheControl = require('express-cache-controlfreak').cacheControl
Default export; importing as a named export is wrong. The package uses module.exports directly.
default
const cacheControl = require('express-cache-controlfreak')
const { cacheControl } = require('express-cache-controlfreak')
CommonJS default import works; named destructuring fails because there is no named export.
TypeScript type import
import type { RequestHandler } from 'express' // no types exported from package
import { CacheControlOptions } from 'express-cache-controlfreak'
Package does not ship TypeScript definitions; you must provide your own or use @types. There is no exported type for options.

Demonstrates two usage patterns: middleware with options and chainable res.cacheControl with pattern and options.

import express from 'express'; import cacheControl from 'express-cache-controlfreak'; const app = express(); // Use as middleware: set max-age to 5 minutes app.get('/api', cacheControl({ maxAge: 300 }), (req, res) => { res.json({ message: 'cached for 5 minutes' }); }); // Chainable method on res app.get('/chain', (req, res) => { res.cacheControl('public', { maxAge: 600 }) .status(200) .send('Hello world'); }); app.listen(3000);
Debug
Known issues
gotchaThe 'no-store' pattern sets 'no-cache, no-store' (includes no-cache), not just 'no-store'.
fix
Use explicit options { noStore: true, noCache: false } to avoid including no-cache, or manually set header.
affects: <=0.1.2
gotchaThe 'no-store' pattern sets 'no-cache, no-store' (includes no-cache), not just 'no-store'.
fix
Use explicit options { noStore: true, noCache: false } to avoid including no-cache, or manually set header.
affects: <=0.1.2
gotchaCalling res.cacheControl() with no arguments throws an error; pattern and options are both optional but at least one must be provided.
fix
Always pass either a pattern string, an options object, or both.
affects: <=0.1.2
deprecatedPackage is no longer actively maintained; last publish in 2014. Use modern alternatives like 'helmet' or manual Cache-Control headers.
fix
Consider using 'helmet' or writing res.set('Cache-Control', 'public, max-age=31557600') directly.
affects: *
Errors
Common errors & fixes
TypeError: cacheControl is not a function
Importing package incorrectly (e.g., named import instead of default) or missing require/import of default export.
fix
Use const cacheControl = require('express-cache-controlfreak'); (CommonJS) or import cacheControl from 'express-cache-controlfreak' (ESM).
Cannot read property 'cacheControl' of undefined
Middleware not applied before using res.cacheControl, or wrong request/response object.
fix
Ensure app.use(cacheControl()) or route-specific middleware is placed before the handler that uses res.cacheControl.
Error: pattern must be a string or number
Passing an object as the first argument instead of a pattern; pattern should be a string or number.
fix
Use cacheControl({ maxAge: 300 }) for options-only, or cacheControl('public', { maxAge: 300 }) for both.
ReferenceError: ms is not defined
Missing ms dependency (especially in older projects); ms is used internally and must be installed.
fix
Run npm install ms; or use numeric maxAge values instead of time strings.
Upgrade
Version history
0.1.2latest on npm
Audit
Dependencies
expressrequiredPeer dependency; middleware works only with Express 4+
msoptionalUsed to parse time strings for max-age (e.g., '1h')
Agent activity
2 hits · last 30 days
node
2
Resources
express-cache-controlfreak — npm install express-cache-controlfreak · libregistry