Under The Hood
frontend nextjs Next.js 14+ / 15

On-Demand ISR: revalidateTag & Cache Tags Indexing

Last updated
Prerequisites:
Next.js Data Cache
Fetch API caching options
  • nextjs
  • isr
  • caching
  • revalidateTag
  • data-cache
  • app-router

Read at your depth

The practical view

`revalidateTag` allows you to purge specific entries from the Next.js Data Cache on demand. When fetching data, attach a tag: `fetch(url, { next: { tags: ['products'] } })`. When a mutation occurs (like in a Server Action), call `revalidateTag('products')`. The next time someone requests that data, Next.js refreshes it from the upstream source instead of serving stale cached data.

The same idea in other frameworks

react equivalent
Custom cache invalidation using TanStack Query `queryClient.invalidateQueries({ queryKey })`.

Legacy vs modern

Time-based polling vs On-Demand Tag Revalidation

Time-based polling serves stale data or wastes compute; on-demand tag revalidation invalidates data immediately upon mutation.

before → after
Time-based Revalidation
fetch(url, { next: { revalidate: 3600 } }); // ❌ OLD: Stale for up to 1 hour
Tag-based Invalidation
revalidateTag('products'); // ✅ NEW: Instant on-demand cache purge

Interview gotchas

Context

Interviewers want to see if you understand the scope of cache invalidation.

The mechanical answer

`revalidatePath` purges both the Full Route Cache and Data Cache for a specific URL path structure (including or excluding sub-routes). `revalidateTag` purges the underlying Data Cache entries across any page or component in the application that fetched data using that tag, without being bound to a single URL path.

Trap

`revalidatePath` can cause over-invalidation of unrelated data on a page, whereas `revalidateTag` surgically invalidates only the shared entity.

Under The Hood — a multi-depth technical interview hub.

Third-party licenses Press ⌘ K to search.