Next.js Discord

Discord Forum

revalidation increases response times

Answered
Arboreal ant posted this in #help-forum
Open in Discord
Arboreal antOP
So i am fetching data from a third party api and i have cache: 'force-cache' and next: { revalidate: 20 }, so from what i understand when you request the page if it has been less then 20 seconds from the last cache it will serve the cached data, if not it will fetch the new data in the background and serve it the next time you load the page so it shouldn't increase the response time when its fetching the new data, my problem is, when 20 seconds pass and i refresh the page it takes 900ms and serves cashed data when i refresh again it serves the new data in only 200 ms, why is this? as i understand it should do it in the background instead of it deleying the page load when fetching the updated data.
Answered by Toyger
as i understand it should do it in the background
nope, it only create cache with lifetime of 20 seconds, if after 20 seconds no one will open page with request it will never make request to your api.
so it kill cache after 20 seconds, someone request page, new cache with 20 seconds lifetime created, and next 20 seconds cache served.
View full answer

1 Reply

Toyger
as i understand it should do it in the background
nope, it only create cache with lifetime of 20 seconds, if after 20 seconds no one will open page with request it will never make request to your api.
so it kill cache after 20 seconds, someone request page, new cache with 20 seconds lifetime created, and next 20 seconds cache served.
Answer