TypeScript
Public
Revalidate a Next.js Cache Tag after Mutation
Mark tagged data stale after a Server Action changes the underlying records.
#nextjs
#revalidation
#server-actions
#caching
TypeScript
// app/actions/posts.ts
'use server';
import { revalidateTag } from 'next/cache';
export async function publishPost(postId: string) {
const post = await db.post.update({
where: {
id: postId,
},
data: {
published: true,
},
});
revalidateTag('posts', 'max');
return {
id: post.id,
published: post.published,
};
}