Capítulo 182 de 456
Invalidate a cache tag on-demand from inside a Server Action, forcing the next request to wait for fresh data instead of serving stale content. Purpose-built for read-your-own-writes UX (e.g. immediately showing a newly created post).
tag immediately; can only be called from a Server Action.fetch(url, { next: { tags: ['posts'] } }) or cacheTag('posts') inside a 'use cache' function.'use server'
import { updateTag } from 'next/cache'
import { redirect } from 'next/navigation'
export async function createPost(formData: FormData) {
const post = await db.post.create({ data: { /* ... */ } })
updateTag('posts')
updateTag(`post-${post.id}`)
redirect(`/posts/${post.id}`)
}
revalidateTag em Route Handlers.updateTag é exclusivo de Server Actions; para Route Handlers/webhooks use revalidateTag.revalidateTag com profile="max" (stale-while-revalidate), updateTag nunca serve conteúdo obsoleto: a próxima requisição espera o dado fresco.redirect() para o padrão clássico "criar → invalidar → redirecionar já com dado atualizado".