-
-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Support stale-while-revalidate #514
fix: Support stale-while-revalidate #514
Conversation
Codecov Report
@@ Coverage Diff @@
## main #514 +/- ##
=======================================
Coverage 99.81% 99.81%
=======================================
Files 17 17
Lines 528 544 +16
Branches 166 174 +8
=======================================
+ Hits 527 543 +16
Misses 1 1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Hey @richardgarnier and @Embraser01, thanks for your work! I'll be pointing out some things that I think should change, but I'm open to discussion :) |
With that, we may introduce a problem due to misleading usage. Not anyone who uses axios-cache-interceptor should understand all behaviors. By doing this, their axios calls will return stale data when it shouldn't. He already expects that As not using the This will lead to an behavior in a UI similar to the following:
That's why I created the I'm ok to changing the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry if I was a bit strict :) open to discussions if you want :)
Thanks for the review.
I disagree with this interpretation, because stale-while-revalidate explicitly allows reusing the value as if it was fresh. If treating the data as fresh while it is stale is a mistake, then the mistake is on the server side, and not on the implementation of the cache strategy. For reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#stale-while-revalidate
No worries. |
Suuuuper thanks for your time in this PR! Sorry that it took too long (I moved to a state 930 miles away) for me to review. |
About the hydrate discussion, took a time to search about it and still din't find a way to solve it with good DX. I'm searching second opinions and implementations out there, like http-cache-semantics. |
This PR fixes #512
Note: this probably generate conflicts with #510
Also, I'm not completely convinced about the
hydrate
implementation. Currently, when we have a stale value we do the following:To me, this should be the opposite, thus:
This would allow for RFC compliance while also allowing users to get the fresh data as soon as it is available should they need it (when used on a server it does not necessarily make sense to use the double return technique).
However, should we want to make the change above, I think the current PR can still be merged and the change above be made in another PR.