Use revalidatePath
to invalidate the cache for a particular route
For example, to invalidate a specific URL:
import { revalidatePath } from 'next/cache'
export async function updatePost(id: string) {
// Do something...
// Then revalidate
revalidatePath('/blog/post-1')
}
To invalidate a URL pattern:
import { revalidatePath } from 'next/cache'
export async function updatePost(id: string) {
// Do something...
// Then revalidate
revalidatePath('/blog/[slug]')
}
See the revalidatePath
API reference to learn more.
You can also use revalidateTag
if you need to cache data based on tags.