revalidateTag
revalidateTag allows you to invalidate cached data on-demand for a specific cache tag.
Usage
revalidateTag can be called in Server Functions and Route Handlers.
revalidateTag cannot be called in Client Components or Middleware, as it only works in server environments.
Good to know
revalidateTag marks tagged data as stale, but fresh data is only fetched when pages using that tag are next visited. This means calling revalidateTag will not immediately trigger many revalidations at once. The invalidation only happens when any page using that tag is next visited.
Parameters
tag: A string representing the cache tag associated with the data you want to revalidate. Must not exceed 256 characters. This value is case-sensitive.
You can add tags to fetch as follows:
Returns
revalidateTag does not return a value.
Relationship with revalidatePath
revalidateTag invalidates data with specific tags across all pages that use those tags, while revalidatePath invalidates specific page or layout paths.
Good to know
These functions serve different purposes and may need to be used together for comprehensive data consistency. For detailed examples and considerations, see Relationship with revalidateTag.
Examples
Server Action
Route Handler
Last updated