Demo
layout.tsx
Cached Data Display (Client)

Current Data

This data is cached and updates when revalidated

1234

Total Views

Invalid Date

Last Updated

Invalid Date

Fetched At

Revalidation Controls

Trigger Revalidation

Each button increments views and revalidates using a different method

Revalidation Methods Comparison
MethodScopeUse Case
revalidatePath(path)Single route or layout subtreeAfter form submission on specific page
revalidateTag(tag)All fetches with matching tagCMS webhook, cross-page data updates
{ next: { revalidate: 60 } }Individual fetch requestTime-based freshness (ISR pattern)
Server Action Pattern
'use server';
import { revalidatePath } from 'next/cache';

export async function updateProduct(
  id: string,
  data: ProductData
) {
  await db.product.update(id, data);
  
  // Revalidate the product page
  revalidatePath(`/products/${id}`);
}
Tagged Fetch Pattern
// In Server Component
const data = await fetch(url, {
  next: { 
    tags: ['products', 'featured'],
    revalidate: 3600 // 1 hour
  }
});

// In Server Action
revalidateTag('products'); // All tagged fetches refresh
Best Practice

Prefer revalidateTag over revalidatePath for data that appears on multiple pages. Tags give you fine-grained control over which cached data to invalidate without knowing all the routes that use it.