The cache working process is set up incorrectly (or correctly?) #60129
Unanswered
vordgi
asked this question in
App Router
Replies: 2 comments
-
PR with a solution option - #60130 |
Beta Was this translation helpful? Give feedback.
0 replies
-
Video examples of bug After the second request, the backend returns large data. "Request number" and "Load data, data length:" were logged from route handler. "Render page" from page segment Development (2x). In the middle I did force reload. dev.mp4Production (2x). I changed revalidation time for fetch to 5s prod.mp4 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In case of cache writing errors, it will be impossible to retrieve up-to-date data until the cache is successfully written. Meanwhile, requests for up-to-date data will continue.
Example:
We load a blog. All articles are loaded immediately. At some point, an additional pack of articles is added, but they are not displayed on the service. There are no errors, requests are being made, and the backend returns correct data.
Why? Here's the answer: the data was 1.9MB, but it became more than 2MB. Next.js (for some reason) does not display this error in production.
Repository with the bug - https://github.com/vordgi/next-fetch-cache-bug
A highly simplified caching algorithm:
I tried to create a diagram (please don't judge it too harshly, there is no need to go into detail) -
So, if there is an error in the third step, only the second step will be executed, repeatedly returning outdated data, but still making requests for up-to-date data (without a revalidation period, meaning much more frequently).
When repeating in development mode, it gets even more interesting - with a hard refresh (adding the cache-control: no-cache header), freshly loaded data is displayed, and then with a regular refresh, old data is read from the cache since the new data could not be written.
However, if a cache writing error occurs in the first step, only the first step will be repeated, completing the expected process.
Here's how the process can be structured in simplified form:
A more detailed diagram (highlighting changes in orange squares) -
Beta Was this translation helpful? Give feedback.
All reactions