How to add tag cache to a page ?
Unanswered
Masai Lion posted this in #help-forum
Masai LionOP
Next.js allow to tag "fetch" request.
It's also possible to define revalidation time to a specific page.
Any way to tag a specific page to be able to invalidate his cache with revalidateTag function ?
Actually the only way i found to tag a page is to create a dummy fetch function inside of it
For example:
const Page= async () => {
const respsonse = await fetch('https://google.com', {
next: { tags: ["my-tag"] },
});
}
It's also possible to define revalidation time to a specific page.
Any way to tag a specific page to be able to invalidate his cache with revalidateTag function ?
Actually the only way i found to tag a page is to create a dummy fetch function inside of it
For example:
const Page= async () => {
const respsonse = await fetch('https://google.com', {
next: { tags: ["my-tag"] },
});
}
2 Replies
Transvaal lion
The TTL for router caching is predefined by default https://nextjs.org/docs/app/building-your-application/caching#duration-3 however, the next paragraph of that link (https://nextjs.org/docs/app/building-your-application/caching#invalidation-1) does provide a few easy methods of invalidating routes/pages, i.e.
revalidatePath, if that is what you are looking forMasai LionOP
The goal was to revalidate page by tag instead of path. But it seems there is no way to tag a page.
For example I tag following page with tag "foo"
/news/example
/bar
/another
Then I can invalidate this page cache with revalidateTag
For example I tag following page with tag "foo"
/news/example
/bar
/another
Then I can invalidate this page cache with revalidateTag