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
+5-2
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,8 @@
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. It's aware of many tricky details such as the `Vary` header, proxy revalidation, and authenticated responses.
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
+
It also implements [RFC 5861](https://tools.ietf.org/html/rfc5861), implementing `stale-if-error` and `stale-while-revalidate`.
5
+
It's aware of many tricky details such as the `Vary` header, proxy revalidation, and authenticated responses.
Returns approximate time in _milliseconds_ until the response becomes stale (i.e. not fresh).
105
107
106
108
After that time (when `timeToLive() <= 0`) the response might not be usable without revalidation. However, there are exceptions, e.g. a client can explicitly allow stale responses, so always check with `satisfiesWithoutRevalidation()`.
109
+
`stale-if-error` and `stale-while-revalidate` extend the time to live of the cache, that can still be used if stale.
107
110
108
111
### `toObject()`/`fromObject(json)`
109
112
@@ -131,7 +134,7 @@ Use this method to update the cache after receiving a new response from the orig
131
134
132
135
-`policy` — A new `CachePolicy` with HTTP headers updated from `revalidationResponse`. You can always replace the old cached `CachePolicy` with the new one.
133
136
-`modified` — Boolean indicating whether the response body has changed.
134
-
- If `false`, then a valid 304 Not Modified response has been received, and you can reuse the old cached response body.
137
+
- If `false`, then a valid 304 Not Modified response has been received, and you can reuse the old cached response body. This is also affected by `stale-if-error`.
135
138
- If `true`, you should use new response's body (if present), or make another request to the origin server without any conditional headers (i.e. don't use `revalidationHeaders()` this time) to get the new resource.
0 commit comments