Issue with caching in Next.js: revalidateTag() not working as expected
Unanswered
Bee posted this in #help-forum
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. 🙏
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. 🙏
6 Replies
BeeOP
when I added revalidate, then everything started working properly. I wonder why?
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.
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
@Arinji 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.
BeeOP
1 – I was just testing trying to figure out what the problem was. I removed it in the adjacent screenshot)
But why it only works when you add "revalidate" I still don't understand
But why it only works when you add "revalidate" I still don't understand
Try the 2nd option
Revalidate works cause when you go to the page, you probs manually refreshed the page