cache-control
Format and parse HTTP Cache-Control header
Getting started
$ npm install @tusbar/cache-control
API
This library exposes a CacheControl
class and two shortcut methods: parse()
and format()
.
const {parse} = require('@tusbar/cache-control')
parse()
takes Cache-Control
HTTP header value and returns a CacheControl
instance.
For example, parse('max-age=31536000, public')
will return
CacheControl {
maxAge: 31536000,
sharedMaxAge: null,
maxStale: false,
maxStaleDuration: null,
minFresh: null,
immutable: false,
mustRevalidate: false,
noCache: false,
noStore: false,
noTransform: false,
onlyIfCached: false,
private: false,
proxyRevalidate: false,
public: true }
format(cacheControl)
const {format} = require('@tusbar/cache-control')
format()
takes a CacheControl
instance (or similar object) and returns a Cache-Control
HTTP header value.
For example, format({maxAge: 31536000, public: true})
will return
max-age=31536000, public
Example usage
res.setHeader('Cache-Control', format({
public: true,
immutable: true
}))
License
MIT