- Notifications
You must be signed in to change notification settings - Fork8
Format and parse HTTP Cache-Control header
License
tusbar/cache-control
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Format and parse HTTP Cache-Control header
$ npm install @tusbar/cache-control
This library exposes aCacheControl
class and two shortcut methods:parse()
andformat()
.
const{parse}=require('@tusbar/cache-control')
parse()
takes aCache-Control
HTTP header value and returns aCacheControl
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,staleIfError:null,staleWhileRevalidate:null}
const{format}=require('@tusbar/cache-control')
format()
takes aCacheControl
instance (or similar object) and returns aCache-Control
HTTP header value.
For example,format({maxAge: 31536000, public: true})
will return
max-age=31536000,public
res.setHeader('Cache-Control',format({public:true,immutable:true}))
Why another cache-control library?
None of the existing libraries focus on just parsing theCache-Control
headers. There are some that expose Express (or connect-like) middlewares, and some unmaintained other ones that do rudimentary parsing of the header. The idea of this module is to parse the header according to the RFC with no further analysis or integration.
cachecontrol
: Golang HTTP Cache-Control Parser and Interpretation
MIT
╚⊙ ⊙╝ ╚═(███)═╝ ╚═(███)═╝╚═(███)═╝ ╚═(███)═╝ ╚═(███)═╝ ╚═(███)═╝
About
Format and parse HTTP Cache-Control header