Next.js Discord

Discord Forum

Issue with caching in Next.js: revalidateTag() not working as expected

Unanswered
Bee posted this in #help-forum
Open in Discord
Avatar
BeeOP
Hi everyone! 👋

I’m working on a Next.js project and using fetch with tags to manage caching. The problem is that after calling revalidateTag(), the cache doesn’t reset, and the data remains the same as it was before.

I’m confident that everything is set up correctly, but maybe I’m missing something. Are there any additional steps or configurations needed to make sure the cache gets properly invalidated?

Has anyone faced a similar issue? I’d really appreciate any advice or insights on how to resolve this. 🙏
Image

6 Replies

Avatar
BeeOP
when I added revalidate, then everything started working properly. I wonder why?
Image
Avatar
2 things
1) why are you using headers.. nextjs extends the fetch object to add caching directly. You do not need to add cache control headers (that's probs why it's breaking)

2) Revalidate tag changes it's functionality if you call it from a server action or not. If it's not a server action you also need to do a router.refresh() on the client.
@Bee
Avatar
Try the 2nd option
Revalidate works cause when you go to the page, you probs manually refreshed the page