How to revalidate the data cache on deployment
Answered
Morelet’s Crocodile posted this in #help-forum
Morelet’s CrocodileOP
I'm building my SSG website with Sanity headless cms and have set up webhook to trigger a redeployment on new content being published so it would generate a new pages with updated content.
The problem: When I leave the fetch request by default, the data is cached across deployments so it would use the data from the last deployment instead of the newly updated data. So I added
What I've tried: I've been crawling through this guide https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config but most of it just essentially impose 1 caching strategy on every fetch request on a layout or page
Thanks in advance
The problem: When I leave the fetch request by default, the data is cached across deployments so it would use the data from the last deployment instead of the newly updated data. So I added
cache: no-store to the fetch option but that made it so that the page become dynamic and would fetch the new data before it's ready for production and erroring out, moreover I'd like the pages to be SSG so that's wouldn't help.What I've tried: I've been crawling through this guide https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config but most of it just essentially impose 1 caching strategy on every fetch request on a layout or page
Thanks in advance
Answered by joulev
The data cache is persisted across deployments, can’t do anything about it.
But you can change your deployment workflow. Instead of making a new deployment, you simply ping a route handler that calls revalidatePath/revalidateTag, revalidating your data cache.
But you can change your deployment workflow. Instead of making a new deployment, you simply ping a route handler that calls revalidatePath/revalidateTag, revalidating your data cache.
4 Replies
I recommend you to read this: https://nextjs.org/docs/app/building-your-application/caching
@Morelet’s Crocodile I'm building my SSG website with Sanity headless cms and have set up webhook to trigger a redeployment on new content being published so it would generate a new pages with updated content.
The problem: When I leave the fetch request by default, the data is cached across deployments so it would use the data from the last deployment instead of the newly updated data. So I added `cache: no-store` to the fetch option but that made it so that the page become dynamic and would fetch the new data before it's ready for production and erroring out, moreover I'd like the pages to be SSG so that's wouldn't help.
What I've tried: I've been crawling through this guide https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config but most of it just essentially impose 1 caching strategy on every fetch request on a layout or page
Thanks in advance
The data cache is persisted across deployments, can’t do anything about it.
But you can change your deployment workflow. Instead of making a new deployment, you simply ping a route handler that calls revalidatePath/revalidateTag, revalidating your data cache.
But you can change your deployment workflow. Instead of making a new deployment, you simply ping a route handler that calls revalidatePath/revalidateTag, revalidating your data cache.
Answer
@joulev The data cache is persisted across deployments, can’t do anything about it.
But you *can* change your deployment workflow. Instead of making a new deployment, you simply ping a route handler that calls revalidatePath/revalidateTag, revalidating your data cache.
Morelet’s CrocodileOP
That would use the on demand revalidation strategy from @Anay-208 's answer right? Thanks for the help 
