fix(cache): remove cached value when revalidation results in an error… #2611
+28
−10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
… or invalid value
🔗 Linked issue
#1992
❓ Type of change
📚 Description
When an SWR revalidation occurs the existing value is not initially deleted from the cache storage. Instead it only overwritten after the revalidation is complete. However, if the revalidation results in an error or invalid value, the original value remains in the cache storage. This can result in a stale value persisting in the cache throughout many revalidations, long after it should have been replaced.
Another approach could be to preemptively delete the stored value. This may simplify the implementation, but it means that other requests which arrive during the revalidation will not be served the cached value.
📝 Checklist