
Security News
Follow-up and Clarification on Recent Malicious Ruby Gems Campaign
A clarification on our recent research investigating 60 malicious Ruby gems.
cacheable-middleware
Advanced tools
Middleware component to set cache headers on responses from an Express or Connect server
Middleware component to set cache headers on responses from an Express or Connect server.
Install as an NPM module:
npm install cacheable-middleware
The cacheable middleware can be used in two ways - by adding it to the express or connect server, the response will
add a new method cacheFor( millisecondsDuration )
that will add the cache headers to cache this particular response
for the specified number of milliseconds.
// add cache middleware to add cacheFor method to responses
app.use(require('cache-middleware')());
// add a route that sends a file and sets headers to cache for one day
app.get('/', function(req, res) {
res.cacheFor(86400000).sendfile(__dirname + '/index.html');
});
// add a route that sends a file and sets headers to cache for six months
app.get('/long-cache', function(req, res) {
res.cacheFor(6, 'months').sendfile(__dirname + '/index.html');
});
To automatically set the cache headers for a particular duration for a path, set the duration when the middleware is added:
// add cache middleware to add cacheFor method to responses
// and default the cache headers on each response to one day
app.use('/static', require('cache-middleware')(86400000));
// alternative syntax
app.use('/static', require('cache-middleware')(1 'day'));
For conveninece, durations can be supplied as any arguments that can be received by Moment.js.
Upgrading to version 1.x requires node >= 6 to support the use of ES6
FAQs
Middleware component to set cache headers on responses from an Express or Connect server
The npm package cacheable-middleware receives a total of 8 weekly downloads. As such, cacheable-middleware popularity was classified as not popular.
We found that cacheable-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.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.
Research
/Security News
A malicious Go module posing as an SSH brute forcer exfiltrates stolen credentials to a Telegram bot controlled by a Russian-speaking threat actor.