You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+12-5
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Can I cache this? [](https://travis-ci.org/kornelski/http-cache-semantics)
2
2
3
-
`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.
3
+
`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
4
It also implements [RFC 5861](https://tools.ietf.org/html/rfc5861), implementing `stale-if-error` and `stale-while-revalidate`.
5
5
It's aware of many tricky details such as the `Vary` header, proxy revalidation, and authenticated responses.
6
6
@@ -67,7 +67,6 @@ const options = {
67
67
cacheHeuristic:0.1,
68
68
immutableMinTimeToLive:24*3600*1000, // 24h
69
69
ignoreCargoCult:false,
70
-
trustServerDate:true,
71
70
};
72
71
```
73
72
@@ -79,8 +78,6 @@ If `options.shared` is `true` (default), then the response is evaluated from a p
79
78
80
79
If `options.ignoreCargoCult` is true, common anti-cache directives will be completely ignored if the non-standard `pre-check` and `post-check` directives are present. These two useless directives are most commonly found in bad StackOverflow answers and PHP's "session limiter" defaults.
81
80
82
-
If `options.trustServerDate` is false, then server's `Date` header won't be used as the base for `max-age`. This is against the RFC, but it's useful if you want to cache responses with very short `max-age`, but your local clock is not exactly in sync with the server's.
83
-
84
81
### `storable()`
85
82
86
83
Returns `true` if the response can be stored in a cache. If it's `false` then you MUST NOT store either the request or the response.
@@ -189,8 +186,18 @@ if (!oldPolicy.satisfiesWithoutRevalidation(newRequest)) {
189
186
- Requests for stale data.
190
187
- Filtering of hop-by-hop headers.
191
188
- Basic revalidation request
189
+
-`stale-if-error`
192
190
193
191
## Unimplemented
194
192
195
-
- Merging of range requests, If-Range (but correctly supports them as non-cacheable)
193
+
- Merging of range requests, `If-Range` (but correctly supports them as non-cacheable)
196
194
- Revalidation of multiple representations
195
+
196
+
### Trusting server `Date`
197
+
198
+
Per the RFC, the cache should take into account the time between server-supplied `Date` and the time it received the response. The RFC-mandated behavior creates two problems:
199
+
200
+
* Servers with incorrectly set timezone may add several hours to cache age (or more, if the clock is completely wrong).
201
+
* 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
+
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