-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Undeprecate revalidate APIs and rename expire APIs (#73193)
As discussed we are removing the deprecated field from `revalidateTag` and `revalidatePath` as they aren't going away anytime soon and the new `expire` APIs will have slightly different semantics so not a 1-1 rename with no arguments change anymore. We are also adding the `unstable_` prefix for `expireTag`/`expirePath` while we iterate on them so it's clear they will change. --------- Co-authored-by: Zack Tanner <1939140+ztanner@users.noreply.github.com>
- Loading branch information
Showing
54 changed files
with
253 additions
and
240 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
docs/01-app/03-api-reference/04-functions/unstable_expireTag.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
--- | ||
title: unstable_expireTag | ||
description: API Reference for the unstable_expireTag function. | ||
version: unstable | ||
--- | ||
|
||
`unstable_expireTag` allows you to purge [cached data](/docs/app/building-your-application/caching) on-demand for a specific cache tag. | ||
|
||
> **Good to know**: | ||
> | ||
> - `unstable_expireTag` is available in both [Node.js and Edge runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes). | ||
> - `unstable_expireTag` only invalidates the cache when the path is next visited. This means calling `unstable_expireTag` with a dynamic route segment will not immediately trigger many expirations at once. The invalidation only happens when the path is next visited. | ||
## Reference | ||
|
||
### Parameters | ||
|
||
```tsx | ||
unstable_expireTag(...tags: string[]): void; | ||
``` | ||
|
||
- `tags`: String arguments representing the cache tags associated with the data you want to revalidate. Must be less than or equal to 256 characters each. This value is case-sensitive. | ||
|
||
You can add tags to `fetch` as follows: | ||
|
||
```tsx | ||
fetch(url, { next: { tags: [...] } }); | ||
``` | ||
|
||
### Returns | ||
|
||
`unstable_expireTag` does not return a value. | ||
|
||
## Examples | ||
|
||
### Server Action | ||
|
||
You can invoke `unstable_expireTag` in a Server Action: | ||
|
||
```ts filename="app/actions.ts" switcher | ||
'use server' | ||
|
||
import { unstable_expireTag } from 'next/cache' | ||
|
||
export default async function submit() { | ||
await addPost() | ||
unstable_expireTag('posts', 'blog') | ||
} | ||
``` | ||
|
||
```js filename="app/actions.js" switcher | ||
'use server' | ||
|
||
import { unstable_expireTag } from 'next/cache' | ||
|
||
export default async function submit() { | ||
await addPost() | ||
unstable_expireTag('posts', 'blog') | ||
} | ||
``` | ||
|
||
### Route Handler | ||
|
||
You can invoke `unstable_expireTag` in a Route Handler: | ||
|
||
```ts filename="app/api/revalidate/route.ts" switcher | ||
import type { NextRequest } from 'next/server' | ||
import { unstable_expireTag } from 'next/cache' | ||
|
||
export async function GET(request: NextRequest) { | ||
const tag = request.nextUrl.searchParams.get('tag') | ||
unstable_expireTag(tag) | ||
return Response.json({ revalidated: true, now: Date.now() }) | ||
} | ||
``` | ||
|
||
```js filename="app/api/revalidate/route.js" switcher | ||
import { unstable_expireTag } from 'next/cache' | ||
|
||
export async function GET(request) { | ||
const tag = request.nextUrl.searchParams.get('tag') | ||
unstable_expireTag(tag) | ||
return Response.json({ revalidated: true, now: Date.now() }) | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.