advanced
Revalidation
Refresh stale cached content by time, path, tag, mutation, deploy, or explicit operational trigger.
Revalidation refreshes cached data or routes after time intervals, on-demand path invalidation, or cache tags tied to entities. `revalidatePath`, `revalidateTag`, and fetch `next.tags` connect writes to reads.
import { revalidateTag } from 'next/cache';
export async function updatePost(id: string) {
await savePost(id);
revalidateTag('posts');
}
Operational triggers include webhooks, admin actions, and deploy pipelines — not only time-based windows.
On interviews: design invalidation for a CMS edit that affects a listing page and detail pages.
Common pitfalls: forgetting to tag fetches, over-broad path revalidation, and no monitoring of stale user reports.
The trade-off is precise invalidation work versus blast-radius of path-based clears.
Checklist:
- Tag fetches that share invalidation scope.
- Revalidate after successful mutations.
- Prefer tags over wiping entire sites.
- Log revalidation in admin workflows.