Middleware for meddling with Cache-Control headers
npm install express-cache-controllerA simple and lightweight module for managing cache control headers from within your application. It also tries to provide a simple set of rules for common use cases such as setting 'max-age=0' when 'no-cache' is present by default.
js
app.use(cacheControl({
noCache: true
}));
`
Creates a cache-control header of no-cache, max-age=0Usage
To start using cacheControl, just use the middleware in your application:
`js
app.use(cacheControl());
`$3
When initialising the middleware you can set default options when you use it in your application:
`js
app.use(cacheControl({
maxAge: 5
}));
`$3
Just set the cacheControl property of the response object after the cacheControl() middleware is loaded:
`js
app.use(cacheControl({ maxAge: 60 }));
app.get('/', function (req, res, next){
res.cacheControl = {
maxAge: 30
}; res.send('hai');
});
`This is useful in error conditions where you can setup cache headers before and after a request is processed:
`js
app.use(cacheControl({ maxAge: 60} ));
app.get('/', function (req, res, next) {
next(Error('BOOM!'));
});
app.use(function (err, req, res, next) {
res.cacheControl = {
maxAge: 5
}; res.status(500).send('oh no!');
});
``