connect-cache-control2
Connect Middleware to handle cache control with ease
Usage
To use use the middleware just import the withCacheControl
function and create a middleware for the routes or routes you want.
const withCacheControl = withCacheControl; app;
The possible options to pass are:
private
: Set to true to use 'private' if not will be 'public'maxAge
: Set the amount to use for max-age. If the value is a number is interpreted as seconds. If it's a string we use ms module to parse it.noStore
: set 'no-store' if truenoCache
: set 'no-cache' if truemustRevalidate
: set 'must-revalidate' if true
To understand what each option means, you can check: Beginners Guide to HTTP Cache Headers
Without the Middleware
If you just need to generate a 'Cache-Control' valid value, you can use toCacheControl(options)
function.
Just do:
const toCacheControl = toCacheControl; app;
Shortcut for noCache
Typically, to avoid proxy cache to store and cache a resource when we not intend to, we should set 'Cache-Control' to tell that. We defined an already configured middleware for that.
const noCache = noCache; app;
Which is the same as: