revalidateTag()
Invalidates all cached fetches associated with a given cache tag.
Syntax
import { revalidateTag } from 'next/cache'; revalidateTag(tag) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
tag | string | Yes | The cache tag previously attached to fetch requests via `next: { tags: [...] }`. |
Returns
void — Marks tagged cache entries stale.
Examples
// Tag data when fetching
async function getProducts() {
return fetch('https://api.example.com/products', {
next: { tags: ['products'] },
}).then((r) => r.json())
}
'use server'
import { revalidateTag } from 'next/cache'
export async function createProduct(data: FormData) {
await db.products.create(data)
revalidateTag('products')
}
Notes
Tag-based revalidation is more granular than `revalidatePath`: every
fetch tagged with the same string is invalidated wherever it is used.
Tags are attached via the `next.tags` option on `fetch` or
`unstable_cache`. Call from Server Actions/Route Handlers only.