Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-cache-controller

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-cache-controller

Middleware for meddling with Cache-Control headers

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

express-cache-controller

A 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.

Example

Configuring noCache easily:

app.use(cacheControl({
  noCache: true
}));

Creates a cache-control header of no-cache, max-age=0

Usage

To start using cacheControl, just use the middleware in your application:

app.use(cacheControl());

Default Cache Headers

When initialising the middleware you can set default options when you use it in your application:

app.use(cacheControl({
    maxAge: 5
}));

Overriding Defaults

Just set the cacheControl property of the response object after the cacheControl() middleware is loaded:

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:

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!');
});

Options

NameValueDescription
privateBooleanAdds 'private' flag, overrides 'public' option
publicBooleanAdds 'public' flag
noStoreBooleanAdds 'no-store' flag and includes noCache
noCacheBooleanAdds 'no-cache' flag, sets maxAge to 0 and removes sMaxAge, staleIfError and staleWhileRevalidate
noTransformBooleanAdds 'no-transform' flag
mustRevalidateBooleanAdds 'must-revalidate' flag and removes staleIfError and staleWhileRevalidate
staleIfErrorNumberAdds 'stale-if-error=%d' flag
staleWhileRevalidateNumberAdds 'stale-while-revalidate=%d' flag
maxAgeNumberAdds 'max-age=%d' flag
sMaxAgeNumberAdds 's-maxage=%d' flag

Keywords

FAQs

Package last updated on 30 Oct 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc