Part 11 / Topic 2 of 6
revalidatePath — invalidate by route, no tag required
revalidatePath doesn't need a cacheTag at all — it invalidates by the route's own file path. /mandi/top-categories (Part 10, section 4) has no tag of its own, which makes it the cleanest possible demonstration: a tiny Route Handler is the entire trigger.
// harness/app/api/mandi/revalidate-top-categories/route.ts
import { revalidatePath } from "next/cache";
export async function POST() {
revalidatePath("/mandi/top-categories");
return Response.json({ revalidated: true, path: "/mandi/top-categories" });
}
/mandi/top-categories is fully static (○), so under normal traffic every request is fast — the 500ms simulated query behind it only ever runs once, at build time. Verified for real against a next build && next start:
$ curl -s -o /dev/null -w "%{time_total}s\n" http://localhost:PORT/mandi/top-categories # 1st
0.027s
$ curl -s -o /dev/null -w "%{time_total}s\n" http://localhost:PORT/mandi/top-categories # 2nd
0.015s
$ curl -s -X POST http://localhost:PORT/api/mandi/revalidate-top-categories
{"revalidated":true,"path":"/mandi/top-categories"}
$ curl -s -o /dev/null -w "%{time_total}s\n" http://localhost:PORT/mandi/top-categories # right after revalidatePath
0.559s
$ curl -s -o /dev/null -w "%{time_total}s\n" http://localhost:PORT/mandi/top-categories # the one after that
0.017s
The request immediately after revalidatePath pays the full 500ms query cost again — revalidatePath doesn't pre-compute anything, it only marks the cached entry stale, exactly as the installed docs state: "Route Handlers: marks the path for revalidation. The revalidation is done on the next visit to the specified path." The request after that is fast again, because the fresh result is now cached. Full file: examples/01-revalidate-top-categories-route.ts.
Done here? The practice set for Part 11 — including the solutions — is on the part page.