CodShot
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,
  };
}

Snippet actions

CodShot user
CodShot user
Updated: 2026-08-06 18:36
Public snippets
0
Forks
CodShot AI Help
Ask about CodShot features, plans, workspace, AI limits, referrals, and public help topics.
Hi! I can help you understand how CodShot works. What would you like to know?
For account-specific or sensitive issues, please open a support ticket. Open support