
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
connect-cache-control-middleware
Advanced tools
A Connect/Express middleware for setting max-age and stale-while-revalidate Cache-Control headers
A Connect/Express middleware for consistently setting Cache-Control headers
npm i --save connect-cache-control-middleware
var cacheControlMiddleware = require('connect-cache-control-middleware');
// creates a middleware instance that prevents caching
var preventCaching = cacheControlMiddleware.create();
// creates a middleware instance that caches routes
var allowCaching = cacheControlMiddleware.create({
maxAge: 600,
staleWhileRevalidate: 86400
});
app.get('/dont-cache-me', [preventCaching], someHandlerFunction);
app.use(allowCaching);
cacheControlMiddleware.create([cacheControlConfig])
Returns a new instance of the middleware handler which can be passed to Connect.
If cacheControlConfig
is omitted, then the middleware sets the following headers on each request:
Cache-Control: 'no-cache, no-store, must-revalidate'
User-Cache-Control: 'no-cache, no-store, must-revalidate'
Pragma: 'no-cache'
Expires: '0'
Otherwise, it will set Cache-Control
and User-Cache-Control
to:
max-age=<cacheControlConfig.maxAge>
stale-while-revalidate=<cacheControlConfig.staleWhileRevalidate>
cacheControlMiddleware.buildCacheControlHeader(cacheControlConfig)
A helper function, used internally, to consistently build Cache-Control
headers. This is exposed publicly if one requires to set headers outside of the middleware chain e.g. express-remote-handlebars
.
As with the create
method, cacheControlConfig
should be an object exposing respective maxAge
and staleWhileRevalidate
properties.
This method returns a String
.
npm i
npm test
package.json
(semver please!)git tag release-<version number>
git push origin --tags
FAQs
A Connect/Express middleware for setting max-age and stale-while-revalidate Cache-Control headers
The npm package connect-cache-control-middleware receives a total of 3 weekly downloads. As such, connect-cache-control-middleware popularity was classified as not popular.
We found that connect-cache-control-middleware demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.