Next.js Discord

Discord Forum

Is it possible to purge the data cache on redeploy? This was possible when using page router

Answered
Northwestern Crow posted this in #help-forum
Open in Discord
Northwestern CrowOP
Hi folks 👋 . Thanks for reading. Here's some context:
- The content team manually triggers a redeploy through a vercel deploy hook whenever they update the content. Otherwise the pages should be statically generated and the data should be cached indefinitely.
- I can disable build cache through the hook. But now since the data cache persists through deployments, it will still get stale data when building.
- I can sign in into Vercel dashboard and manually purge the cache there but the content team won't be able to do so.
- I don't want it to have a timed revalidation or completely opt out of caching since the content will be updated infrequently.

My question is, is there some sort of setting on Vercel for this (automatically purge data cache on redeploy)? Or is my only option now to create a revalidating API route and call it every time before triggering the redeploy?

It was just a simple deploy url call button from the CMS side, so this whole thing now looks kinda undesirable.
Answered by joulev
Don’t rebuild the entire site when you just need new data from the cms. Make a web hook that runs revalidatePath/revalidateTag instead https://nextjs-forum.com/post/1248519899647578133
View full answer

9 Replies

Answer
As for the option to purge data cache on build, no it doesn’t exist unfortunately
Northwestern CrowOP
Thanks and yeah, that's unfortunate. The site has a relatively small amount of pages that is infrequently updated, so we were happy with the simple setup.
One more question: If I revalidate the data cache (let's say on cms data change), but data is fetched with a force-cache and no revalidation period, it should only show up when redeployed (which trigger build step), right? The deployment step is there so that the content team can decide when they're ready, after preview and stuff.
Northwestern CrowOP
Hmmm, that's interesting. A fine-grain automatic webhook on content updates is out of the question if it makes the page get new data immediately in our case. I think I will just call an api route to revalidate all instead of redeploy for now. That's a lot of useful information, thanks a bunch 🙌
Then the moment they hit that button, users will start to see new content
Doesn’t mean users get to see new content as soon as it is available without the cms team’s green light
Northwestern CrowOP
Oh yeah, I got it. I was just thinking about setting an automatic content trigger on saved if it works the other way like I thought. But yeah, a single revalidate call will solve it now.