4.0.20 • Published 4 months ago

cacheability v4.0.20

Weekly downloads
5
License
MIT
Repository
github
Last release
4 months ago

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.

4.0.19

4 months ago

4.0.20

4 months ago

4.0.18

5 months ago

4.0.4

7 months ago

4.0.7

7 months ago

4.0.6

7 months ago

4.0.1

9 months ago

4.0.0

9 months ago

4.0.3

9 months ago

4.0.2

9 months ago

4.0.9

7 months ago

4.0.8

7 months ago

3.0.2

9 months ago

4.0.10

6 months ago

4.0.15

5 months ago

4.0.12

6 months ago

4.0.11

6 months ago

4.0.14

6 months ago

4.0.13

6 months ago

3.0.1

4 years ago

3.0.0

5 years ago

2.0.10

5 years ago

2.0.9

5 years ago

2.0.8

5 years ago

2.0.7

5 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.61

6 years ago

0.0.60

6 years ago

0.0.59

6 years ago

0.0.57

6 years ago

0.0.56

6 years ago

0.0.55

6 years ago

0.0.54

6 years ago

0.0.53

6 years ago

0.0.52

6 years ago

0.0.51

6 years ago

0.0.50

6 years ago

0.0.49

6 years ago

0.0.48

6 years ago

0.0.47

6 years ago

0.0.46

6 years ago

0.0.45

6 years ago

0.0.44

6 years ago

0.0.43

6 years ago

0.0.42

6 years ago

0.0.40

6 years ago

0.0.39

6 years ago

0.0.38

6 years ago

0.0.37

6 years ago

0.0.36

6 years ago

0.0.35

6 years ago

0.0.34

6 years ago

0.0.33

6 years ago

0.0.32

6 years ago

0.0.31

6 years ago

0.0.30

6 years ago

0.0.29

6 years ago

0.0.28

6 years ago

0.0.27

6 years ago

0.0.26

6 years ago

0.0.25

6 years ago

0.0.24

6 years ago

0.0.23

6 years ago

0.0.22

6 years ago

0.0.21

6 years ago

0.0.20

6 years ago

0.0.18

6 years ago

0.0.17

6 years ago

0.0.16

6 years ago

0.0.15

6 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

7 years ago