Next.js Discord

Discord Forum

Is it Possible to Schedule Revalidation?

Unanswered
West African Lion posted this in #help-forum
Open in Discord
West African LionOP
My app pulls events from a Google calendar and displays them.

At the moment, I'm running into an issue where after an event ends, nothing changes on the website. I want it to revalidate so the past event gets clearned and the next events are pulled. Is this something I can achieve with a server action or route handler? I already have an endpoint that will revalidate and google hits it anytime something changes with the calendar, but if nothing changes, no revalidation takes place so the old-stale event still shows up.

9 Replies

@West African Lion My app pulls events from a Google calendar and displays them. At the moment, I'm running into an issue where after an event ends, nothing changes on the website. I want it to revalidate so the past event gets clearned and the next events are pulled. Is this something I can achieve with a server action or route handler? I already have an endpoint that will revalidate and google hits it anytime something changes with the calendar, but if nothing changes, no revalidation takes place so the old-stale event still shows up.
what do you think about revalidating your page after time? Like revalidate your page every 30 minutes. When you access the page, the new events will be pulled and displayed and cached for 30 minutes. So you have one google calendar api request in 30 minutes. If you not visit the page, there are also no additional api requests, because you are not actively accessing the page and if you actively visit the site, then new data get pulled and old will be hidden/deleted/...
@West African Lion So I knew about time based revalidation, but figured that only revalidating after an event ended would be the ideal solution since it will only purge the cache when it is needed
with the page time based revalidation it will be also only revalidated, when the path is visited. So you don't access the page for a month, there are no revalidations
@B33fb0n3 with the page time based revalidation it will be also only revalidated, when the path is visited. So you don't access the page for a month, there are no revalidations
West African LionOP
That still means that if everything stays the same, people visiting the site every 30 minutes will have a longer load time, no? If it isn't possible, that's that, but I wanted to ask to be sure. Even a "short" time of 30 minutes would mean that someone looking at the website can view it with incorrect data like "we are open" when they closed 20 minutes ago. Maybe I can run some small function anytime the website is accessed and revalidate it if the current event's end time has passed? Is that more reasonable?
@West African Lion That still means that if everything stays the same, people visiting the site every 30 minutes will have a longer load time, no? If it isn't possible, that's that, but I wanted to ask to be sure. Even a "short" time of 30 minutes would mean that someone looking at the website can view it with incorrect data like "we are open" when they closed 20 minutes ago. Maybe I can run some small function anytime the website is accessed and revalidate it if the current event's end time has passed? Is that more reasonable?
people visiting the site every 30 minutes will have a longer load time, no?
no, because they will see the old version and in the background the new version will be created. The next one who visits (or the person reloads) will see the correct informations.

But that's not a good practice. If I would be you, I would load the page via SSR and fetch the data from the google api
West African LionOP
I wish! It only sends them out when an event is modified (created, deleted, archived, un-archived, and updated).

Is this what you were talking about earlier?
https://nextjs.org/docs/app/building-your-application/caching#opting-out-1