Détail du package

cacheability

badbatch1.3kMIT4.0.30

A utility class to parse, store and print http cache headers.

cacheability, cacheControl, etag, headers

readme

cacheability

A utility class to parse, store and print http cache headers.

Build and publish License: MIT npm version

Installation

npm add cacheability

Documentation

Initialization

The constructor takes either a Headers instance, object literal of header key/values, cache-control header field value or Cacheability metadata object, parses it, if required, and then stores the result on the Cacheability instance's metadata property.

import { Cacheability } from "cacheability";

const headers = new Headers({
  "cache-control": "public, max-age=60",
  "content-type": "application/json",
  "etag": "33a64df551425fcc55e4d42a148795d9f25f89d4",
});

const cacheability = new Cacheability({ headers });

const { cacheControl, etag, ttl } = cacheability.metadata;
// cacheControl is { maxAge: 60, public: true }
// etag is 33a64df551425fcc55e4d42a148795d9f25f89d4
// ttl is 1516060712991 if Date.now is 1516060501948

Properties

metadata

The property holds the Cacheability instance's parsed cache headers data, including cache control directives, etag, and a derived TTL timestamp.

Methods

checkTTL

The method checks whether the TTL timestamp stored in the Cacheability instance is still valid, by comparing it to the current timestamp.

const cacheability = new Cacheability({ cacheControl: "public, max-age=3" });

// One second elapses...

const isValid = cacheability.checkTTL();
// isValid is true

// Three seconds elapse...

const isStillValid = cacheability.checkTTL();
// isStillValid is false

printCacheControl

The method prints a cache-control header field value based on the Cacheability instance's metadata. The max-age and/or s-maxage are derived from the TTL stored in the metadata.

const cacheability = new Cacheability({ cacheControl: "public, max-age=60, s-maxage=60" });

// Five seconds elapse...

const cacheControl = cacheability.printCacheControl();
// cacheControl is "public, max-age=55, s-maxage=55"

Changelog

Check out the features, fixes and more that go into each major, minor and patch version.

License

Cacheability is MIT Licensed.

changelog

Changelog

4.0.30 (2025-06-13)

Chores

  • minor update (73edc1a6)

4.0.29 (2025-05-28)

Bug Fixes

  • vulnerbilities (d507ad8d)

4.0.28 (2025-05-28)

Build System / Dependencies

  • deps:
    • bump cross-spawn (#85) (dd3eaa6a)
    • bump @eslint/plugin-kit (#84) (c0328220)

4.0.27 (2024-11-20)

Build System / Dependencies

  • deps-dev:
    • bump @repodog/eslint-config from 9.0.7 to 9.0.10 (#83) (ec72e283)
    • bump @swc/core from 1.8.0 to 1.9.1 (#82) (98516791)
    • bump rollup from 4.24.3 to 4.24.4 (#79) (3b2f0cf1)
    • bump @swc/core from 1.7.42 to 1.8.0 (#80) (6663c85b)
    • bump @types/node from 22.8.7 to 22.9.0 (#81) (a5ad30bd)

Bug Fixes

  • remove postinstall script (c27a941d)
  • remove dependabot version updates (4baaf6d3)

4.0.26 (2024-11-03)

Chores

  • bump deps (2c7c6ea9)

4.0.25 (2024-11-02)

Chores

  • bump deps (b87476c9)

Bug Fixes

  • minor update to package json (5b7ad703)

4.0.24 (2024-11-02)

Build System / Dependencies

  • deps-dev:
    • bump @types/node from 22.8.5 to 22.8.6 (#74) (4521a0fe)
    • bump @swc/core from 1.7.40 to 1.7.42 (#76) (23b8abbb)
    • bump eslint from 9.13.0 to 9.14.0 (#77) (f1a6c44a)
    • bump @swc/jest from 0.2.36 to 0.2.37 (#69) (e62f5681)
    • bump rollup from 4.24.0 to 4.24.3 (#70) (15501d34)
    • bump @types/node from 22.7.9 to 22.8.5 (#73) (4efe5516)
    • bump @swc/core from 1.7.39 to 1.7.40 (#72) (f336cea2)
  • deps: bump core-js from 3.38.1 to 3.39.0 (#75) (8ae439ea)

Chores

  • bump deps (e99c543d)
  • bump repodog typescript version (da1ccb9d)

New Features

  • add mise and upgrade deps (70c7a3b2)

Bug Fixes

  • add husky commit message file (1dfbbff0)

4.0.23 (2024-10-30)

Build System / Dependencies

  • deps-dev:
    • bump @types/jest from 29.5.13 to 29.5.14 (#61) (3217e090)
    • bump rollup from 4.24.2 to 4.24.3 (#68) (dc36b1fc)
    • bump @swc/core from 1.7.39 to 1.7.40 (#64) (8a4ebea1)
    • bump @types/node from 22.7.8 to 22.8.4 (#67) (50e0922c)
    • bump rollup from 4.24.0 to 4.24.2 (#66) (682a69ef)
    • bump @swc/core from 1.7.36 to 1.7.39 (#60) (ea545ff6)
    • bump @types/node from 22.7.7 to 22.7.8 (#59) (cacf61d2)
    • bump @swc/core from 1.7.28 to 1.7.36 (#58) (ee32ce51)
    • bump typescript from 5.6.2 to 5.6.3 (#57) (bd511565)
    • bump @types/node from 22.7.2 to 22.7.7 (#56) (1333fac6)
    • bump eslint from 9.11.1 to 9.13.0 (#54) (dfc89bd0)
    • bump del-cli from 5.1.0 to 6.0.0 (#51) (bc4f6d7e)
    • bump rollup from 4.22.4 to 4.24.0 (#49) (cc9edbba)
  • deps:
    • bump micromatch from 4.0.5 to 4.0.8 (#55) (2f7d381f)
    • bump @types/lodash-es from 4.17.9 to 4.17.12 (#48) (f62d04de)

Chores

  • exclude idea/ folder (8045541c)

Bug Fixes

  • lock file (17a48939)
  • add corejs as dependency (40bc2086)
  • remove unused deps (863e4f54)

Other Changes

  • remove unused deps" (a953c9c5)

4.0.22 (2024-09-26)

Chores

  • upgrade deps (bd2e6280)
  • minor update to package json (90a6c95b)

4.0.21 (2024-09-25)

Build System / Dependencies

  • deps-dev:
    • bump ejs from 3.1.9 to 3.1.10 (#43) (44ae2f6b)
    • bump ws from 8.14.2 to 8.17.1 (#44) (1fd795c4)
    • bump follow-redirects from 1.15.5 to 1.15.6 (#42) (de6fb2de)

Chores

  • minor sorting issue (26881b7b)
  • fix vulnerabilities (bf6fe8e7)
  • upgrade deps (5ec16ade)

4.0.20 (2024-01-12)

Chores

  • upgrade deps (cb12cdd7)

4.0.19 (2024-01-12)

Chores

  • upgrade deps (b50c4f31)

4.0.18 (2023-12-16)

Bug Fixes

  • version of pnpm used in pipeline (18b65f79)

4.0.17 (2023-12-16)

Bug Fixes

  • bump node version (e888e1ee)
  • update esm cjs support (4ce446e3)

4.0.16 (2023-12-16)

Bug Fixes

  • legacy link was not removed (5c14710c)

Other Changes

  • add import and require types" (f58af576)

Tests

  • add import and require types (f52bf088)

4.0.15 (2023-11-28)

Bug Fixes

  • update installation example to npm (41b161ea)
  • typo in package json (9e4f449d)

4.0.14 (2023-11-22)

New Features

  • upgrade syncpack (1fe26084)

4.0.13 (2023-11-22)

Bug Fixes

  • exports require file ext (96496725)

4.0.12 (2023-11-22)

Chores

  • upgrade repodog cli (477bfdc1)

4.0.11 (2023-11-22)

Reverts

  • syncpack changes (ac0b0850)

4.0.10 (2023-11-20)

Build System / Dependencies

  • deps-dev: bump @babel/traverse from 7.22.10 to 7.23.2 (#40) (6f75259e)

Refactors

  • update syncpack and use exports map (7bbe6118)

4.0.9 (2023-10-12)

Bug Fixes

  • remove redundant deps (cdf6fd05)

4.0.8 (2023-10-12)

Chores

  • upgrade deps (63f016db)

4.0.7 (2023-10-11)

4.0.6 (2023-10-11)

Bug Fixes

  • add lock file (2d6c7551)

4.0.5 (2023-10-11)

Refactors

  • move lodash to peer dep (70c00f0f)

4.0.4 (2023-09-28)

Refactors

  • replace lodash with lodash-es (be99907c)
  • remove js doc private annotations (5e24a965)

4.0.3 (2023-08-15)

Bug Fixes

  • badge readme (678d3e64)

4.0.2 (2023-08-15)

Chores

  • config updates (307b5e52)

Bug Fixes

  • update repository url to fix npm readme (ac64f1be)

4.0.1 (2023-08-14)

Bug Fixes

  • typo in docs (732d8968)

4.0.0 (2023-08-14)

Chores

  • trigger rebuild (d5c3b326)

New Features

  • move to esmodules (352a4ac6)