Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Next.js 16+ · Function

revalidateTag

Invalidates cached data associated with a tag using stale-while-revalidate behavior. In Next.js 16, pass a cacheLife profile such as "max" as the second argument.

Since
16.0.0

How it works

Call revalidateTag from server-side code with a cache tag and a revalidation profile. It marks matching cached data stale, then the next request serves stale content while revalidation runs; after the profile's allowed stale period, a request waits for fresh data.

Syntax

revalidateTag(tag: string, profile: string | { expire?: number }): void;

Parameters

NameTypeDescription
tagstringCache tag associated with the cached data to invalidate. It is case-sensitive and limited to 256 characters.
profilestring | { expire?: number }Controls how long stale content may be served. Use "max", another cacheLife profile, or an object with an expiration in seconds.

Returns

void

Key points

  • It invalidates cached entries associated with one cache tag.
  • The function is available in server-side functions and Route Handlers.
  • Calling it changes matching entries to stale rather than synchronously rebuilding them.
  • The next request gets stale content while Next.js refreshes the data in the background.
  • The recommended max profile provides stale-while-revalidate behavior for a long stale window.
  • For a custom duration, provide an object such as { expire: 3600 }.

Common mistakes

  • Use it only in Server Functions or Route Handlers; Client Components and Proxy are unsupported.
  • Keep tags within 256 characters and use consistent casing.
  • Pass the second profile argument; the old one-argument call is deprecated in Next.js 16.
  • Use updateTag in a Server Action when read-your-writes or immediate expiration is required.

Example: Invalidate tagged article data

import { revalidateTag } from 'next/cache'

export async function POST() {
  // Update the data source here.
  revalidateTag('articles', 'max')
  return Response.json({ revalidated: true })
}

This Route Handler marks cached entries tagged articles as stale; the next request receives stale data while fresh data is generated.

When to use it

Refresh published content

A blog post or documentation page changes and a small delay before fresh content appears is acceptable.

Invalidate related entries

Several cached functions share one tag and should be invalidated together.

React to external updates

A Route Handler receives a webhook from a content or product system.

  • cacheLife
  • revalidatePath
  • updateTag

Source: revalidateTag. Checked 2026-10-15.