Socket
Socket
Sign inDemoInstall

cache-control-esm

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

cache-control-esm

Format and parse HTTP Cache-Control header


Version published
Maintainers
1
Weekly downloads
55,500
decreased by-34.27%

Weekly downloads

Readme

Source

cache-control

Format and parse HTTP Cache-Control header

:warning: This is a fork of the original @tusbar/cache-control package.

This package uses export default instead of module.exports to expose the code and was specifically modified to be bundled by axios-cache-adapter.

Getting started

$ npm install @rascarlito/cache-control

API

This library exposes a CacheControl class and two shortcut methods: parse() and format().

parse(header)

import { parse } from '@rascarlito/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)

import { format } from '@rascarlito/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
}))

FAQ

Why another cache-control library?

None of the existing libraries focus on just parsing the Cache-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

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

Keywords

FAQs

Last updated on 21 May 2019

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc