Skip to content

Commit 0b95122

Browse files
authored
docs: revalidateTag immediate expiration in Route Handlers (#85223)
Further precision to revalidateTag signature, and escape hatch for route handlers w/ immediate revalidation
1 parent 5ce476a commit 0b95122

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

docs/01-app/03-api-reference/04-functions/revalidateTag.mdx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ The revalidation behavior depends on whether you provide the second argument:
2525
2626
## Parameters
2727

28-
```tsx
29-
revalidateTag(tag: string, profile?: string): void;
28+
```ts
29+
revalidateTag(tag: string, profile?: string | { expire?: number }): void;
3030
```
3131

3232
- `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.
33-
- `profile`: A string that specifies the revalidation behavior. The recommended value is `"max"` which provides stale-while-revalidate semantics. For advanced usage, this can be configured to any cache life profile that your application defines.
33+
- `profile`: A string that specifies the revalidation behavior. The recommended value is `"max"` which provides stale-while-revalidate semantics, or any of the other default or custom profiles defined in [`cacheLife`](/docs/app/api-reference/config/next-config-js/cacheLife). Alternatively, you can pass an object with an `expire` property for custom expiration behavior.
3434

3535
Tags must first be assigned to cached data. You can do this in two ways:
3636

@@ -64,6 +64,8 @@ async function getData() {
6464
6565
## Examples
6666

67+
The following examples demonstrate how to use `revalidateTag` in different contexts. In both cases, we're using `profile="max"` to mark data as stale and use stale-while-revalidate semantics, which is the recommended approach for most use cases.
68+
6769
### Server Action
6870

6971
```ts filename="app/actions.ts" switcher
@@ -128,3 +130,5 @@ export async function GET(request) {
128130
})
129131
}
130132
```
133+
134+
> **Good to know**: For webhooks or third-party services that need immediate expiration, you can pass `{ expire: 0 }` as the second argument: `revalidateTag(tag, { expire: 0 })`. This pattern is necessary when external systems call your Route Handlers and require data to expire immediately. For all other cases, it's recommended to use [`updateTag`](/docs/app/api-reference/functions/updateTag) in Server Actions for immediate updates instead.

0 commit comments

Comments
 (0)