Implement cache revalidation
See original GitHub issueToday, cacheable, unchanged resources are not stored in the browser cache - regardless of the Cache-Control response headers that are applied in Workers. In other words, it’s impossible to get a 304 Not Modified response (it is, however, possible to get Chrome to return the resource from memory cache).
There are two reasons for this:
- Resources stored in Cache API do not include a
Last-Modified
orEtag
response header - The cacheKey tied to each resource would strip the
If-Modified-Since
orIf-None-Match
header before querying the cache API (right now, the browser wouldn’t even send these headers because of the first reason)
Solutions Coming soon
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:12 (8 by maintainers)
Top Results From Across the Web
Keeping things fresh with stale-while-revalidate - web.dev
stale-while-revalidate helps developers balance between immediacy—loading cached content right away—and freshness—ensuring updates to the cached ...
Read more >Cache Control Headers and Revalidation - Traffic Control
When a response is expired it usually doesn't get deleted from the cache, but, when a request comes in that would have hit...
Read more >Stale-while-revalidate Data Fetching with React Hooks: A Guide
A stale cache is a cache that is not suitable for use as it contains outdated data. In the context of HTTP, this...
Read more >UX Patterns: Stale-While-Revalidate - InfoQ
stale-while-revalidate helps developers balance between immediacy—loading cached content right away—and freshness—ensuring updates to the cached ...
Read more >Staleness and revalidation - Fastly Developer Hub
Background revalidation process flow. When a cache lookup results in a stale object that is within a stale-while-revalidate period (scenario 2 in the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @budparr! Appreciate the input.
I do think that the
options
parameter should supportetag
generation. As @victoriabernard92 mentioned (and you observed)cache.match()
already supports conditional revalidation, permitted anetag
is provided by an origin server.A solution here needs to consider the following:
etag
)Here is my plan:
digest()
method that can be used to hash the actual content bodies. So we can kill two birds with one stone here by hashing the response body contents upon cache insertion likedigest('SHA-1', '<html>...')
. This ensures a new version of a file will always have a differentetag
than its predecessorSHA1(HASH-OF-BODY)-{content-encoding}
such that content-encoding differences are handled properlyHey @EatonZ - thanks for flagging this. It got de-prioritized over the last month or so.
I have a preliminary solution complete but need to talk to @EverlastingBugstopper because it does not make use of the wrangler-generated manifest. Should be able to make a PR by end of week. With respect to your comment about CPU: of course, those are the only considerations here 😃