question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support stale-while-revalidate and stale-if-error

See original GitHub issue

Hi @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 the stale-if-error directive and return true if the response is a 5XX and the stale response can be used.
  • A new method satisfiesWithRevalidation() would check the stale-while-revalidate directive and return true 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:open
  • Created 4 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
kornelskicommented, Feb 9, 2020

If you’re implementing it in parallel with an actual HTTP client I’m confident it’ll make sense.

0reactions
sithmelcommented, Feb 25, 2020
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found