Skip to content

Commit ed83aec

Browse files
committed
Explain trust server date
1 parent 1b35980 commit ed83aec

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

README.md

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Can I cache this? [![Build Status](https://travis-ci.org/kornelski/http-cache-semantics.svg?branch=master)](https://travis-ci.org/kornelski/http-cache-semantics)
22

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.
44
It also implements [RFC 5861](https://tools.ietf.org/html/rfc5861), implementing `stale-if-error` and `stale-while-revalidate`.
55
It's aware of many tricky details such as the `Vary` header, proxy revalidation, and authenticated responses.
66

@@ -67,7 +67,6 @@ const options = {
6767
cacheHeuristic: 0.1,
6868
immutableMinTimeToLive: 24 * 3600 * 1000, // 24h
6969
ignoreCargoCult: false,
70-
trustServerDate: true,
7170
};
7271
```
7372

@@ -79,8 +78,6 @@ If `options.shared` is `true` (default), then the response is evaluated from a p
7978

8079
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.
8180

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-
8481
### `storable()`
8582

8683
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)) {
189186
- Requests for stale data.
190187
- Filtering of hop-by-hop headers.
191188
- Basic revalidation request
189+
- `stale-if-error`
192190

193191
## Unimplemented
194192

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

Comments
 (0)