You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/01-app/02-guides/incremental-static-regeneration.mdx
+8-6Lines changed: 8 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -281,17 +281,19 @@ We recommend setting a high revalidation time. For instance, 1 hour instead of 1
281
281
282
282
### On-demand revalidation with `revalidatePath`
283
283
284
-
For a more precise method of revalidation, invalidate pages on-demand with the `revalidatePath` function.
284
+
For a more precise method of revalidation, invalidate cached pages on-demand with the `revalidatePath` function.
285
285
286
-
For example, this Server Action would get called after adding a new post. Regardless of how you retrieve your data in your Server Component, either using `fetch` or connecting to a database, this will immediately clear the cache for the entire route. Unlike time-based revalidation, the next request after on-demand revalidation won't return stale data but will serve the updated version right away and cache it for subsequent requests.
286
+
For example, this Server Action would get called after adding a new post. Regardless of how you retrieve your data in your Server Component, either using `fetch` or connecting to a database, this will invalidate the cache for the entire route. The next request to that route will trigger regeneration and serve fresh data, which will then be cached for subsequent requests.
287
+
288
+
> **Note:**`revalidatePath` invalidates the cache entries but regeneration happens on the next request. If you want to eagerly regenerate the cache entry immediately instead of waiting for the next request, you can use the Pages router [`res.revalidate`](docs/pages/guides/incremental-static-regeneration#on-demand-validation-with-resrevalidate) method. We're working on adding new methods to provide eager regeneration capabilities for the App Router.
287
289
288
290
```ts filename="app/actions.ts" switcher
289
291
'use server'
290
292
291
293
import { revalidatePath } from'next/cache'
292
294
293
295
exportasyncfunction createPost() {
294
-
// Invalidate the /posts route in the cache
296
+
// Invalidate the cache for the /posts route
295
297
revalidatePath('/posts')
296
298
}
297
299
```
@@ -302,7 +304,7 @@ export async function createPost() {
302
304
import { revalidatePath } from'next/cache'
303
305
304
306
exportasyncfunctioncreatePost() {
305
-
// Invalidate the /posts route in the cache
307
+
// Invalidate the cache for the /posts route
306
308
revalidatePath('/posts')
307
309
}
308
310
```
@@ -379,7 +381,7 @@ You can then use `revalidateTag` in a [Server Actions](/docs/app/getting-started
379
381
import { revalidateTag } from'next/cache'
380
382
381
383
exportasyncfunction createPost() {
382
-
// Invalidate all data tagged with 'posts' in the cache
384
+
// Invalidate all data tagged with 'posts'
383
385
revalidateTag('posts')
384
386
}
385
387
```
@@ -390,7 +392,7 @@ export async function createPost() {
390
392
import { revalidateTag } from'next/cache'
391
393
392
394
exportasyncfunctioncreatePost() {
393
-
// Invalidate all data tagged with 'posts' in the cache
The path parameter can point to pages, layouts, or route handlers:
35
35
36
-
-**Pages**: Revalidates the specific page
37
-
-**Layouts**: Revalidates the layout and all pages beneath it
38
-
-**Route Handlers**: Revalidates Data Cache entries accessed within route handlers. For example `revalidatePath("/api/data")`revalidates this GET handler:
36
+
-**Pages**: Invalidates the specific page
37
+
-**Layouts**: Invalidates the layout and all pages beneath it
38
+
-**Route Handlers**: Invalidates Data Cache entries accessed within route handlers. For example `revalidatePath("/api/data")`invalidates this GET handler:
39
39
40
40
```ts filename="app/api/data/route.ts"
41
41
exportasyncfunction GET() {
@@ -51,8 +51,8 @@ export async function GET() {
51
51
52
52
`revalidatePath` and [`revalidateTag`](/docs/app/api-reference/functions/revalidateTag) serve different purposes:
53
53
54
-
-**`revalidatePath`**: Revalidates a specific page or layout path
55
-
-**`revalidateTag`**: Revalidates data with specific tags across all pages that use those tags
54
+
-**`revalidatePath`**: Invalidates a specific page or layout path
55
+
-**`revalidateTag`**: Invalidates data with specific tags across all pages that use those tags
56
56
57
57
When you call `revalidatePath`, only the specified path gets fresh data on the next visit. Other pages that use the same data tags will continue to serve cached data until those specific tags are also revalidated:
58
58
@@ -101,7 +101,7 @@ import { revalidatePath } from 'next/cache'
101
101
revalidatePath('/blog/post-1')
102
102
```
103
103
104
-
This will revalidate one specific URL on the next page visit.
104
+
This will invalidate one specific URL for revalidation on the next page visit.
This will revalidate any URL that matches the provided `page` file on the next page visit. This will _not_ invalidate pages beneath the specific page. For example, `/blog/[slug]` won't invalidate `/blog/[slug]/[author]`.
115
+
This will invalidate any URL that matches the provided `page` file for revalidation on the next page visit. This will _not_ invalidate pages beneath the specific page. For example, `/blog/[slug]` won't invalidate `/blog/[slug]/[author]`.
This will revalidate any URL that matches the provided `layout` file on the next page visit. This will cause pages beneath with the same layout to revalidate on the next visit. For example, in the above case, `/blog/[slug]/[another]` would also revalidate on the next visit.
126
+
This will invalidate any URL that matches the provided `layout` file for revalidation on the next page visit. This will cause pages beneath with the same layout to be invalidated and revalidated on the next visit. For example, in the above case, `/blog/[slug]/[another]` would also be invalidated and revalidated on the next visit.
127
127
128
128
### Revalidating all data
129
129
@@ -133,7 +133,7 @@ import { revalidatePath } from 'next/cache'
133
133
revalidatePath('/', 'layout')
134
134
```
135
135
136
-
This will purge the Client-side Router Cache, and revalidate the Data Cache on the next page visit.
136
+
This will purge the Client-side Router Cache, and invalidate the Data Cache for revalidation on the next page visit.
`revalidateTag`revalidates data with specific tags across all pages that use those tags, while [`revalidatePath`](/docs/app/api-reference/functions/revalidatePath)revalidates specific page or layout paths.
36
+
`revalidateTag`invalidates data with specific tags across all pages that use those tags, while [`revalidatePath`](/docs/app/api-reference/functions/revalidatePath)invalidates specific page or layout paths.
37
37
38
38
> **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](/docs/app/api-reference/functions/revalidatePath#relationship-with-revalidatetag).
0 commit comments