Support stale-while-revalidate and stale-if-error
See original GitHub issueHi @kornelski, thanks for your work on this library, it looks fantastic.
For my use case, I would need the library to support these two Cache-Control
directives. From MDN:
stale-while-revalidate=<seconds>
: Indicates that the client is willing to accept a stale response while asynchronously checking in the background for a fresh one. The seconds value indicates for how long the client is willing to accept a stale response.stale-if-error=<seconds>
: Indicates that the client is willing to accept a stale response if the check for a fresh one fails.
I think it could be implemented in the following way:
satisfiesWithoutRevalidation()
would check thestale-if-error
directive and returntrue
if the response is a 5XX and the stale response can be used.- A new method
satisfiesWithRevalidation()
would check thestale-while-revalidate
directive and returntrue
if the stale response can be used while revalidating in the background. The caller would be expected to make the request while also using the cached response.
If you’re open to these enhancements, I’d be happy to work on them.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Support stale-if-error, stale-while-revalidate · Issue #1083
Probably requires fancy joining & canceling. Stale-while-revalidate is quite tricky because a single request may yield multiple responses.
Read more >Keeping things fresh with stale-while-revalidate - web.dev
Keeping things fresh with stale-while-revalidate. An additional tool to help you balance immediacy and freshness when serving your web app. Jul ...
Read more >RFC 5861: HTTP Cache-Control Extensions for Stale Content
This document defines two independent Cache- Control extensions that allow for such control, stale-if-error and stale-while-revalidate. The stale-if-error ...
Read more >CacheControl
A builder for creating "Cache-Control" HTTP response headers. Adding Cache-Control directives to HTTP responses can significantly improve the client ...
Read more >Stale-While-Revalidate, Stale-If-Error Available Today
Stale-While-Revalidate, Stale-If-Error Available Today. Fastly is excited to announce that as of today, we support stale-while-revalidate ...
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
If you’re implementing it in parallel with an actual HTTP client I’m confident it’ll make sense.
The implementation is ready here: https://github.com/kornelski/http-cache-semantics/pull/30