Next.js Discord

Discord Forum

Reading next/cookies during fetch will cause revalidating whole path instead of given cache keys

Unanswered
Lhasa Apso posted this in #help-forum
Open in Discord
Lhasa ApsoOP
I know this is inteded behaviour, but is there any way to disable it? Reading cookies during fetch is necessary, because I need to forward the session to the BE server, but I don't want to invalidate whole path during this fetch, since it makes no sense for advanced dashboard where are 10+ queries on a single page.

Can I change this revalidate behaviour?

1 Reply

@Lhasa Apso
You could use cache tags and revalidate tag?
fetch(`https://...`, { next: { tags: ['collection'] } })

"Set the cache tags of a resource. Data can then be revalidated on-demand using revalidateTag. The max length for a custom tag is 256 characters and the max tag items is 128."