|
1 | 1 | # Can I cache this? [](https://travis-ci.org/kornelski/http-cache-semantics) |
2 | 2 |
|
| 3 | +> This library is forked from [http-cache-semantics](https://github.com/kornelski/http-cache-semantics), adding support for web standards and exporting in ESM format. |
| 4 | +
|
3 | 5 | `CachePolicy` tells when responses can be reused from a cache, taking into account [HTTP RFC 7234](http://httpwg.org/specs/rfc7234.html) rules for user agents and shared caches. |
4 | 6 | It also implements [RFC 5861](https://tools.ietf.org/html/rfc5861), implementing `stale-if-error` and `stale-while-revalidate`. |
5 | 7 | It's aware of many tricky details such as the `Vary` header, proxy revalidation, and authenticated responses. |
@@ -47,20 +49,19 @@ The key method is `satisfiesWithoutRevalidation(newRequest)`, which checks wheth |
47 | 49 | Request and response must have a `headers` property with all header names in lower case. `url`, `status` and `method` are optional (defaults are any URL, status `200`, and `GET` method). |
48 | 50 |
|
49 | 51 | ```js |
50 | | -const request = { |
51 | | - url: '/', |
| 52 | +const request = new Request('http://localhost/', { |
52 | 53 | method: 'GET', |
53 | 54 | headers: { |
54 | 55 | accept: '*/*', |
55 | 56 | }, |
56 | | -}; |
| 57 | +}); |
57 | 58 |
|
58 | | -const response = { |
| 59 | +const response = new Response(null, { |
59 | 60 | status: 200, |
60 | 61 | headers: { |
61 | 62 | 'cache-control': 'public, max-age=7234', |
62 | 63 | }, |
63 | | -}; |
| 64 | +}); |
64 | 65 |
|
65 | 66 | const options = { |
66 | 67 | shared: true, |
@@ -200,4 +201,4 @@ Per the RFC, the cache should take into account the time between server-supplied |
200 | 201 | * Servers with incorrectly set timezone may add several hours to cache age (or more, if the clock is completely wrong). |
201 | 202 | * Even reasonably correct clocks may be off by a couple of seconds, breaking `max-age=1` trick (which is useful for reverse proxies on high-traffic servers). |
202 | 203 |
|
203 | | -Previous versions of this library had an option to ignore the server date if it was "too inaccurate". To support the `max-age=1` trick the library also has to ignore dates that pretty accurate. There's no point of having an option to trust dates that are only a bit inaccurate, so this library won't trust any server dates. `max-age` will be interpreted from the time the response has been received, not from when it has been sent. This will affect only [RFC 1149 networks](https://tools.ietf.org/html/rfc1149). |
| 204 | +Previous versions of this library had an option to ignore the server date if it was "too inaccurate". To support the `max-age=1` trick the library also has to ignore dates that pretty accurate. There's no point of having an option to trust dates that are only a bit inaccurate, so this library won't trust any server dates. `max-age` will be interpreted from the time the response has been received, not from when it has been sent. This will affect only [RFC 1149 networks](https://tools.ietf.org/html/rfc1149). |
0 commit comments