Purging cached data/routes when content changes.
Skip to solutionKEEP THE
mediumSystem Design
What is on-demand revalidation in Next.js (revalidatePath / revalidateTag)?
586 views
01
Understand the problem
nextjsrevalidationrevalidatetagcaching
02
Attempt it yourself
Sketch your approach before reading the solution — that's what interviews test.
Nudge consolestandby
Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.
03
Study the solution
revalidatePath(path) and revalidateTag(tag) invalidate cached routes/data immediately — typically called from a Server Action or webhook after content changes — so the next request regenerates fresh content instead of waiting for a time-based interval.
Solution ready — 2 min read
Classified // press E to declassify
04
Read the code
Tag data, then revalidate after a mutation
// read with a tag
await fetch('https://api/posts', { next: { tags: ['posts'] } });
// Server Action after creating a post:
'use server';
import { revalidateTag } from 'next/cache';
export async function createPost(data) {
await db.post.create(data);
revalidateTag('posts'); // every page using 'posts' regenerates
}05
Join the discussion
Discussion (0)
Sign in to join the discussion.
No responses yet. Be the first to share what you think.
Transmission complete // awaiting log
KEEP THE
STREAK ALIVE.
Dossier 48 of 95 decoded in the Next.js track. One more won't hurt.