Revalidate on a fetch doesn't send new data when the cache is invalidated?
Unanswered
Cornish Rex posted this in #help-forum
Cornish RexOP
I've a fetch with these options:
For some reason when I open the page a day later it sends out old (stale) data from yesterday.
When I then refresh it works. I guess that next isn't fetching synchronously again if the revalidate time is reached.
Is there any way to force next to not send out old data to the user on first page load?
{
cache: 'force-cache',
next: {
revalidate: 300,
}
}
For some reason when I open the page a day later it sends out old (stale) data from yesterday.
When I then refresh it works. I guess that next isn't fetching synchronously again if the revalidate time is reached.
Is there any way to force next to not send out old data to the user on first page load?
2 Replies
No, that’s expected behavior. Revalidation isn’t instant, requires you to request the page again once the revalidation has been done.
If you call the the
If you trigger a revalidation, you might not see it instantly but other people who requested the page after you triggered the revalidation will get the fresh data.
So basically:
- data needs to become stale
- you need to trigger a revalidation after data became stale
- you need to request fresh data
If you call the the
fetch
function again after the 300 threshold, the fetch call will be marked as stale, so it will revalidate in the background and fetch the new data, but you won’t see this… until you request the page again. Now will get the fresh content. If you trigger a revalidation, you might not see it instantly but other people who requested the page after you triggered the revalidation will get the fresh data.
So basically:
- data needs to become stale
- you need to trigger a revalidation after data became stale
- you need to request fresh data
@Cornish Rex I've a fetch with these options:
{
cache: 'force-cache',
next: {
revalidate: 300,
}
}
For some reason when I open the page a day later it sends out old (stale) data from yesterday.
When I then refresh it works. I guess that next isn't fetching synchronously again if the revalidate time is reached.
Is there any way to force next to not send out old data to the user on first page load?
I guess the way you
And btw, it’s not necessarily to add
force
fresh data on first page load is by making the page dynamic.And btw, it’s not necessarily to add
cache:”force-cache”
if you set up revalidate
with a number.