Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Format and parse HTTP Cache-Control header

License

NotificationsYou must be signed in to change notification settings

tusbar/cache-control

Repository files navigation

Format and parse HTTP Cache-Control header

npm versioncodecovXO code style

CI

TestsRelease

Getting started

$ npm install @tusbar/cache-control

API

This library exposes aCacheControl class and two shortcut methods:parse() andformat().

parse(header)

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}

format(cacheControl)

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

Example usage

res.setHeader('Cache-Control',format({public:true,immutable:true}))

FAQ

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.

See also

  • cachecontrol: Golang HTTP Cache-Control Parser and Interpretation

License

MIT

Miscellaneous

    ╚⊙ ⊙╝  ╚═(███)═╝ ╚═(███)═╝╚═(███)═╝ ╚═(███)═╝  ╚═(███)═╝   ╚═(███)═╝

[8]ページ先頭

©2009-2025 Movatter.jp