0 day streak
javascript / intermediate
Snippet

On-demand Path Revalidation

revalidatePath allows you to purge cached data for a specific route, ensuring users see updated content after a mutation.

snippet.js
javascript
1
2
3
4
5
6
import { revalidatePath } from 'next/cache';
async function updatePost(id) {
await db.update(id);
revalidatePath('/blog');
}
nextjs
Breakdown
1
import { revalidatePath } from 'next/cache'
Imports the utility function used for manual cache invalidation in Next.js.
2
revalidatePath('/blog')
Tells Next.js to re-render and re-cache the blog page on the next request.