Git Product home page Git Product logo

cache-control's Introduction

cache-control

Format and parse HTTP Cache-Control header

npm version codecov XO code style

CI

Tests Release

Getting started

$ npm install @tusbar/cache-control

API

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

parse(header)

const {parse} = require('@tusbar/cache-control')

parse() takes a 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,
  staleIfError: null,
  staleWhileRevalidate: null }

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
}))

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

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

cache-control's People

Contributors

dependabot-preview[bot] avatar tusbar avatar dependabot[bot] avatar dependabot-support avatar delgado3d avatar arthurfiorette avatar johnstableford avatar oliverjash avatar patryks1 avatar semantic-release-bot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.