Next.js caching issue in production and development
Unanswered
GrowWithTalha posted this in #help-forum
Hey everyone, I am working on a project with next.js and sanity.io. The problem I am facing is that when I create a new document in sanity and fetch it next.js. In first time the next.js caches the response and every time I do a change in the sanity.io studio or update a document. The next.js always returns the cached response unless I stop the dev server, delete the .next folder and rerun the server. Can anyone has any soloution to stop fetch caching in next.js?
3 Replies
@GrowWithTalha Hey everyone, I am working on a project with next.js and sanity.io. The problem I am facing is that when I create a new document in sanity and fetch it next.js. In first time the next.js caches the response and every time I do a change in the sanity.io studio or update a document. The next.js always returns the cached response unless I stop the dev server, delete the .next folder and rerun the server. Can anyone has any soloution to stop fetch caching in next.js?
you could create a webhook on sanity and it will make a request to your api endpoint every time you change the content
and you use
revalidatePath or revalidateTag to revalidate the cache inside the api routehttps://github.com/sanity-io/next-sanity?tab=readme-ov-file#cache-revalidation
check their doc for example
check their doc for example