Unverified Commit 071e3170 authored by Delba de Oliveira's avatar Delba de Oliveira Committed by GitHub

docs: Move caching page to deep dive (#78537)

Closes: https://linear.app/vercel/issue/DOC-4608/caching
Redirects: https://github.com/vercel/front/pull/44626
parent f15416d2
...@@ -18,7 +18,7 @@ These Next.js optimizations are enabled by default and require no configuration: ...@@ -18,7 +18,7 @@ These Next.js optimizations are enabled by default and require no configuration:
- **[Code-splitting](/docs/app/building-your-application/routing/linking-and-navigating#how-routing-and-navigation-works):** Server Components enable automatic code-splitting by route segments. You may also consider [lazy loading](/docs/app/guides/lazy-loading) Client Components and third-party libraries, where appropriate. - **[Code-splitting](/docs/app/building-your-application/routing/linking-and-navigating#how-routing-and-navigation-works):** Server Components enable automatic code-splitting by route segments. You may also consider [lazy loading](/docs/app/guides/lazy-loading) Client Components and third-party libraries, where appropriate.
- **[Prefetching](/docs/app/building-your-application/routing/linking-and-navigating#2-prefetching):** When a link to a new route enters the user's viewport, Next.js prefetches the route in background. This makes navigation to new routes almost instant. You can opt out of prefetching, where appropriate. - **[Prefetching](/docs/app/building-your-application/routing/linking-and-navigating#2-prefetching):** When a link to a new route enters the user's viewport, Next.js prefetches the route in background. This makes navigation to new routes almost instant. You can opt out of prefetching, where appropriate.
- **[Static Rendering](/docs/app/building-your-application/rendering/server-components#static-rendering-default):** Next.js statically renders Server and Client Components on the server at build time and caches the rendered result to improve your application's performance. You can opt into [Dynamic Rendering](/docs/app/building-your-application/rendering/server-components#dynamic-rendering) for specific routes, where appropriate. {/* TODO: Update when PPR is stable */} - **[Static Rendering](/docs/app/building-your-application/rendering/server-components#static-rendering-default):** Next.js statically renders Server and Client Components on the server at build time and caches the rendered result to improve your application's performance. You can opt into [Dynamic Rendering](/docs/app/building-your-application/rendering/server-components#dynamic-rendering) for specific routes, where appropriate. {/* TODO: Update when PPR is stable */}
- **[Caching](/docs/app/building-your-application/caching):** Next.js caches data requests, the rendered result of Server and Client Components, static assets, and more, to reduce the number of network requests to your server, database, and backend services. You may opt out of caching, where appropriate. - **[Caching](/docs/app/deep-dive/caching):** Next.js caches data requests, the rendered result of Server and Client Components, static assets, and more, to reduce the number of network requests to your server, database, and backend services. You may opt out of caching, where appropriate.
</AppOnly> </AppOnly>
...@@ -65,7 +65,7 @@ While building your application, we recommend using the following features to en ...@@ -65,7 +65,7 @@ While building your application, we recommend using the following features to en
- **[Route Handlers](/docs/app/building-your-application/routing/route-handlers):** Use Route Handlers to access your backend resources from Client Components. But do not call Route Handlers from Server Components to avoid an additional server request. - **[Route Handlers](/docs/app/building-your-application/routing/route-handlers):** Use Route Handlers to access your backend resources from Client Components. But do not call Route Handlers from Server Components to avoid an additional server request.
- **[Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming):** Use Loading UI and React Suspense to progressively send UI from the server to the client, and prevent the whole route from blocking while data is being fetched. - **[Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming):** Use Loading UI and React Suspense to progressively send UI from the server to the client, and prevent the whole route from blocking while data is being fetched.
- **[Parallel Data Fetching](/docs/app/building-your-application/data-fetching/fetching#parallel-and-sequential-data-fetching):** Reduce network waterfalls by fetching data in parallel, where appropriate. Also, consider [preloading data](/docs/app/building-your-application/data-fetching/fetching#preloading-data) where appropriate. - **[Parallel Data Fetching](/docs/app/building-your-application/data-fetching/fetching#parallel-and-sequential-data-fetching):** Reduce network waterfalls by fetching data in parallel, where appropriate. Also, consider [preloading data](/docs/app/building-your-application/data-fetching/fetching#preloading-data) where appropriate.
- **[Data Caching](/docs/app/building-your-application/caching#data-cache):** Verify whether your data requests are being cached or not, and opt into caching, where appropriate. Ensure requests that don't use `fetch` are [cached](/docs/app/api-reference/functions/unstable_cache). - **[Data Caching](/docs/app/deep-dive/caching#data-cache):** Verify whether your data requests are being cached or not, and opt into caching, where appropriate. Ensure requests that don't use `fetch` are [cached](/docs/app/api-reference/functions/unstable_cache).
- **[Static Images](/docs/app/api-reference/file-conventions/public-folder):** Use the `public` directory to automatically cache your application's static assets, e.g. images. - **[Static Images](/docs/app/api-reference/file-conventions/public-folder):** Use the `public` directory to automatically cache your application's static assets, e.g. images.
</AppOnly> </AppOnly>
......
...@@ -136,7 +136,7 @@ The two layouts would be nested as such: ...@@ -136,7 +136,7 @@ The two layouts would be nested as such:
> - When a `layout.js` and `page.js` file are defined in the same folder, the layout will wrap the page. > - When a `layout.js` and `page.js` file are defined in the same folder, the layout will wrap the page.
> - Layouts are [Server Components](/docs/app/building-your-application/rendering/server-components) by default but can be set to a [Client Component](/docs/app/building-your-application/rendering/client-components). > - Layouts are [Server Components](/docs/app/building-your-application/rendering/server-components) by default but can be set to a [Client Component](/docs/app/building-your-application/rendering/client-components).
> - Layouts can fetch data. View the [Data Fetching](/docs/app/building-your-application/data-fetching) section for more information. > - Layouts can fetch data. View the [Data Fetching](/docs/app/building-your-application/data-fetching) section for more information.
> - Passing data between a parent layout and its children is not possible. However, you can fetch the same data in a route more than once, and React will [automatically dedupe the requests](/docs/app/building-your-application/caching#request-memoization) without affecting performance. > - Passing data between a parent layout and its children is not possible. However, you can fetch the same data in a route more than once, and React will [automatically dedupe the requests](/docs/app/deep-dive/caching#request-memoization) without affecting performance.
> - Layouts do not have access to `pathname` ([learn more](/docs/app/api-reference/file-conventions/layout)). But imported Client Components can access the pathname using [`usePathname`](/docs/app/api-reference/functions/use-pathname) hook. > - Layouts do not have access to `pathname` ([learn more](/docs/app/api-reference/file-conventions/layout)). But imported Client Components can access the pathname using [`usePathname`](/docs/app/api-reference/functions/use-pathname) hook.
> - Layouts do not have access to the route segments below itself. To access all route segments, you can use [`useSelectedLayoutSegment`](/docs/app/api-reference/functions/use-selected-layout-segment) or [`useSelectedLayoutSegments`](/docs/app/api-reference/functions/use-selected-layout-segments) in a Client Component. > - Layouts do not have access to the route segments below itself. To access all route segments, you can use [`useSelectedLayoutSegment`](/docs/app/api-reference/functions/use-selected-layout-segment) or [`useSelectedLayoutSegments`](/docs/app/api-reference/functions/use-selected-layout-segments) in a Client Component.
> - You can use [Route Groups](/docs/app/building-your-application/routing/route-groups) to opt specific route segments in and out of shared layouts. > - You can use [Route Groups](/docs/app/building-your-application/routing/route-groups) to opt specific route segments in and out of shared layouts.
......
...@@ -3,7 +3,7 @@ title: Linking and Navigating ...@@ -3,7 +3,7 @@ title: Linking and Navigating
description: Learn how navigation works in Next.js, and how to use the Link Component and `useRouter` hook. description: Learn how navigation works in Next.js, and how to use the Link Component and `useRouter` hook.
related: related:
links: links:
- app/building-your-application/caching - app/deep-dive/caching
- app/api-reference/config/typescript - app/api-reference/config/typescript
--- ---
...@@ -283,11 +283,11 @@ See the [`<Link>` API reference](/docs/app/api-reference/components/link) for mo ...@@ -283,11 +283,11 @@ See the [`<Link>` API reference](/docs/app/api-reference/components/link) for mo
### 3. Caching ### 3. Caching
Next.js has an **in-memory client-side cache** called the [Router Cache](/docs/app/building-your-application/caching#client-side-router-cache). As users navigate around the app, the React Server Component Payload of [prefetched](#2-prefetching) route segments and visited routes are stored in the cache. Next.js has an **in-memory client-side cache** called the [Router Cache](/docs/app/deep-dive/caching#client-side-router-cache). As users navigate around the app, the React Server Component Payload of [prefetched](#2-prefetching) route segments and visited routes are stored in the cache.
This means on navigation, the cache is reused as much as possible, instead of making a new request to the server - improving performance by reducing the number of requests and data transferred. This means on navigation, the cache is reused as much as possible, instead of making a new request to the server - improving performance by reducing the number of requests and data transferred.
Learn more about how the [Router Cache](/docs/app/building-your-application/caching#client-side-router-cache) works and how to configure it. Learn more about how the [Router Cache](/docs/app/deep-dive/caching#client-side-router-cache) works and how to configure it.
### 4. Partial Rendering ### 4. Partial Rendering
...@@ -311,7 +311,7 @@ Browsers perform a "hard navigation" when navigating between pages. The Next.js ...@@ -311,7 +311,7 @@ Browsers perform a "hard navigation" when navigating between pages. The Next.js
### 6. Back and Forward Navigation ### 6. Back and Forward Navigation
By default, Next.js will maintain the scroll position for backwards and forwards navigation, and re-use route segments in the [Router Cache](/docs/app/building-your-application/caching#client-side-router-cache). By default, Next.js will maintain the scroll position for backwards and forwards navigation, and re-use route segments in the [Router Cache](/docs/app/deep-dive/caching#client-side-router-cache).
### 7. Routing between `pages/` and `app/` ### 7. Routing between `pages/` and `app/`
......
...@@ -77,7 +77,7 @@ export async function generateStaticParams() { ...@@ -77,7 +77,7 @@ export async function generateStaticParams() {
} }
``` ```
The primary benefit of the `generateStaticParams` function is its smart retrieval of data. If content is fetched within the `generateStaticParams` function using a `fetch` request, the requests are [automatically memoized](/docs/app/building-your-application/caching#request-memoization). This means a `fetch` request with the same arguments across multiple `generateStaticParams`, Layouts, and Pages will only be made once, which decreases build times. The primary benefit of the `generateStaticParams` function is its smart retrieval of data. If content is fetched within the `generateStaticParams` function using a `fetch` request, the requests are [automatically memoized](/docs/app/deep-dive/caching#request-memoization). This means a `fetch` request with the same arguments across multiple `generateStaticParams`, Layouts, and Pages will only be made once, which decreases build times.
Use the [migration guide](/docs/app/guides/migrating/app-router-migration#dynamic-paths-getstaticpaths) if you are migrating from the `pages` directory. Use the [migration guide](/docs/app/guides/migrating/app-router-migration#dynamic-paths-getstaticpaths) if you are migrating from the `pages` directory.
......
...@@ -265,7 +265,7 @@ This example caches the result of the database query for 1 hour (3600 seconds). ...@@ -265,7 +265,7 @@ This example caches the result of the database query for 1 hour (3600 seconds).
Next.js uses APIs like `generateMetadata` and `generateStaticParams` where you will need to use the same data fetched in the `page`. Next.js uses APIs like `generateMetadata` and `generateStaticParams` where you will need to use the same data fetched in the `page`.
If you are using `fetch`, requests can be [memoized](/docs/app/building-your-application/caching#request-memoization) by adding `cache: 'force-cache'`. This means you can safely call the same URL with the same options, and only one request will be made. If you are using `fetch`, requests can be [memoized](/docs/app/deep-dive/caching#request-memoization) by adding `cache: 'force-cache'`. This means you can safely call the same URL with the same options, and only one request will be made.
> **Good to know:** > **Good to know:**
> >
...@@ -411,7 +411,7 @@ When fetching data inside components, you need to be aware of two data fetching ...@@ -411,7 +411,7 @@ When fetching data inside components, you need to be aware of two data fetching
#### Sequential data fetching #### Sequential data fetching
If you have nested components, and each component fetches its own data, then data fetching will happen sequentially if those data requests are not [memoized](/docs/app/building-your-application/caching#request-memoization). If you have nested components, and each component fetches its own data, then data fetching will happen sequentially if those data requests are not [memoized](/docs/app/deep-dive/caching#request-memoization).
There may be cases where you want this pattern because one fetch depends on the result of the other. For example, the `Playlists` component will only start fetching data once the `Artist` component has finished fetching data because `Playlists` depends on the `artistID` prop: There may be cases where you want this pattern because one fetch depends on the result of the other. For example, the `Playlists` component will only start fetching data once the `Artist` component has finished fetching data because `Playlists` depends on the `artistID` prop:
......
...@@ -120,7 +120,7 @@ Runtime type-checking will still ensure you don't accidentally pass a function t ...@@ -120,7 +120,7 @@ Runtime type-checking will still ensure you don't accidentally pass a function t
- In Client Components, forms invoking Server Actions will queue submissions if JavaScript isn't loaded yet, prioritizing client hydration. - In Client Components, forms invoking Server Actions will queue submissions if JavaScript isn't loaded yet, prioritizing client hydration.
- After hydration, the browser does not refresh on form submission. - After hydration, the browser does not refresh on form submission.
- Server Actions are not limited to `<form>` and can be invoked from event handlers, `useEffect`, third-party libraries, and other form elements like `<button>`. - Server Actions are not limited to `<form>` and can be invoked from event handlers, `useEffect`, third-party libraries, and other form elements like `<button>`.
- Server Actions integrate with the Next.js [caching and revalidation](/docs/app/building-your-application/caching) architecture. When an action is invoked, Next.js can return both the updated UI and new data in a single server roundtrip. - Server Actions integrate with the Next.js [caching and revalidation](/docs/app/deep-dive/caching) architecture. When an action is invoked, Next.js can return both the updated UI and new data in a single server roundtrip.
- Behind the scenes, actions use the `POST` method, and only this HTTP method can invoke them. - Behind the scenes, actions use the `POST` method, and only this HTTP method can invoke them.
- The arguments and return value of Server Actions must be serializable by React. See the React docs for a list of [serializable arguments and values](https://react.dev/reference/react/use-server#serializable-parameters-and-return-values). - The arguments and return value of Server Actions must be serializable by React. See the React docs for a list of [serializable arguments and values](https://react.dev/reference/react/use-server#serializable-parameters-and-return-values).
- Server Actions are functions. This means they can be reused anywhere in your application. - Server Actions are functions. This means they can be reused anywhere in your application.
...@@ -723,7 +723,7 @@ When an error is thrown, it'll be caught by the nearest `error.js` or `<Suspense ...@@ -723,7 +723,7 @@ When an error is thrown, it'll be caught by the nearest `error.js` or `<Suspense
### Revalidating data ### Revalidating data
You can revalidate the [Next.js Cache](/docs/app/building-your-application/caching) inside your Server Actions with the [`revalidatePath`](/docs/app/api-reference/functions/revalidatePath) API: You can revalidate the [Next.js Cache](/docs/app/deep-dive/caching) inside your Server Actions with the [`revalidatePath`](/docs/app/api-reference/functions/revalidatePath) API:
```ts filename="app/actions.ts" switcher ```ts filename="app/actions.ts" switcher
'use server' 'use server'
......
...@@ -579,7 +579,7 @@ This will make the Next.js server console log ISR cache hits and misses. You can ...@@ -579,7 +579,7 @@ This will make the Next.js server console log ISR cache hits and misses. You can
- ISR is only supported when using the Node.js runtime (default). - ISR is only supported when using the Node.js runtime (default).
- ISR is not supported when creating a [Static Export](/docs/app/guides/static-exports). - ISR is not supported when creating a [Static Export](/docs/app/guides/static-exports).
- If you have multiple `fetch` requests in a statically rendered route, and each has a different `revalidate` frequency, the lowest time will be used for ISR. However, those revalidate frequencies will still be respected by the [Data Cache](/docs/app/building-your-application/caching#data-cache). - If you have multiple `fetch` requests in a statically rendered route, and each has a different `revalidate` frequency, the lowest time will be used for ISR. However, those revalidate frequencies will still be respected by the [Data Cache](/docs/app/deep-dive/caching#data-cache).
- If any of the `fetch` requests used on a route have a `revalidate` time of `0`, or an explicit `no-store`, the route will be [dynamically rendered](/docs/app/building-your-application/rendering/server-components#dynamic-rendering). - If any of the `fetch` requests used on a route have a `revalidate` time of `0`, or an explicit `no-store`, the route will be [dynamically rendered](/docs/app/building-your-application/rendering/server-components#dynamic-rendering).
- Middleware won't be executed for on-demand ISR requests, meaning any path rewrites or logic in Middleware will not be applied. Ensure you are revalidating the exact path. For example, `/post/1` instead of a rewritten `/post-1`. - Middleware won't be executed for on-demand ISR requests, meaning any path rewrites or logic in Middleware will not be applied. Ensure you are revalidating the exact path. For example, `/post/1` instead of a rewritten `/post-1`.
......
...@@ -4,7 +4,7 @@ description: Learn how you can use React Server Components to render parts of yo ...@@ -4,7 +4,7 @@ description: Learn how you can use React Server Components to render parts of yo
related: related:
description: Learn how Next.js caches data and the result of static rendering. description: Learn how Next.js caches data and the result of static rendering.
links: links:
- app/building-your-application/caching - app/deep-dive/caching
--- ---
React Server Components allow you to write UI that can be rendered and optionally cached on the server. In Next.js, the rendering work is further split by route segments to enable streaming and partial rendering, and there are three different server rendering strategies: React Server Components allow you to write UI that can be rendered and optionally cached on the server. In Next.js, the rendering work is further split by route segments to enable streaming and partial rendering, and there are three different server rendering strategies:
...@@ -78,7 +78,7 @@ Dynamic rendering is useful when a route has data that is personalized to the us ...@@ -78,7 +78,7 @@ Dynamic rendering is useful when a route has data that is personalized to the us
> >
> In Next.js, you can have dynamically rendered routes that have both cached and uncached data. This is because the RSC Payload and data are cached separately. This allows you to opt into dynamic rendering without worrying about the performance impact of fetching all the data at request time. > In Next.js, you can have dynamically rendered routes that have both cached and uncached data. This is because the RSC Payload and data are cached separately. This allows you to opt into dynamic rendering without worrying about the performance impact of fetching all the data at request time.
> >
> Learn more about the [full-route cache](/docs/app/building-your-application/caching#full-route-cache) and [Data Cache](/docs/app/building-your-application/caching#data-cache). > Learn more about the [full-route cache](/docs/app/deep-dive/caching#full-route-cache) and [Data Cache](/docs/app/deep-dive/caching#data-cache).
#### Switching to Dynamic Rendering #### Switching to Dynamic Rendering
......
...@@ -107,7 +107,7 @@ For all the available params, see the [API Reference](/docs/app/api-reference/fu ...@@ -107,7 +107,7 @@ For all the available params, see the [API Reference](/docs/app/api-reference/fu
> **Good to know**: > **Good to know**:
> >
> - Both static and dynamic metadata through `generateMetadata` are **only supported in Server Components**. > - Both static and dynamic metadata through `generateMetadata` are **only supported in Server Components**.
> - `fetch` requests are automatically [memoized](/docs/app/building-your-application/caching#request-memoization) for the same data across `generateMetadata`, `generateStaticParams`, Layouts, Pages, and Server Components. React [`cache` can be used](/docs/app/building-your-application/caching#react-cache-function) if `fetch` is unavailable. > - `fetch` requests are automatically [memoized](/docs/app/deep-dive/caching#request-memoization) for the same data across `generateMetadata`, `generateStaticParams`, Layouts, Pages, and Server Components. React [`cache` can be used](/docs/app/deep-dive/caching#react-cache-function) if `fetch` is unavailable.
> - Next.js will wait for data fetching inside `generateMetadata` to complete before streaming UI to the client. This guarantees the first part of a [streamed response](/docs/app/building-your-application/routing/loading-ui-and-streaming) includes `<head>` tags. > - Next.js will wait for data fetching inside `generateMetadata` to complete before streaming UI to the client. This guarantees the first part of a [streamed response](/docs/app/building-your-application/routing/loading-ui-and-streaming) includes `<head>` tags.
## File-based metadata ## File-based metadata
......
...@@ -299,7 +299,7 @@ By default, the Full Route Cache is persistent. This means that the render outpu ...@@ -299,7 +299,7 @@ By default, the Full Route Cache is persistent. This means that the render outpu
There are two ways you can invalidate the Full Route Cache: There are two ways you can invalidate the Full Route Cache:
- **[Revalidating Data](/docs/app/building-your-application/caching#revalidating)**: Revalidating the [Data Cache](#data-cache), will in turn invalidate the Router Cache by re-rendering components on the server and caching the new render output. - **[Revalidating Data](/docs/app/deep-dive/caching#revalidating)**: Revalidating the [Data Cache](#data-cache), will in turn invalidate the Router Cache by re-rendering components on the server and caching the new render output.
- **Redeploying**: Unlike the Data Cache, which persists across deployments, the Full Route Cache is cleared on new deployments. - **Redeploying**: Unlike the Data Cache, which persists across deployments, the Full Route Cache is cleared on new deployments.
### Opting out ### Opting out
......
...@@ -169,7 +169,7 @@ export default function Icon() { ...@@ -169,7 +169,7 @@ export default function Icon() {
> - By default, generated icons are [**statically optimized**](/docs/app/building-your-application/rendering/server-components#static-rendering-default) (generated at build time and cached) unless they use [Dynamic APIs](/docs/app/building-your-application/rendering/server-components#server-rendering-strategies#dynamic-apis) or uncached data. > - By default, generated icons are [**statically optimized**](/docs/app/building-your-application/rendering/server-components#static-rendering-default) (generated at build time and cached) unless they use [Dynamic APIs](/docs/app/building-your-application/rendering/server-components#server-rendering-strategies#dynamic-apis) or uncached data.
> - You can generate multiple icons in the same file using [`generateImageMetadata`](/docs/app/api-reference/functions/generate-image-metadata). > - You can generate multiple icons in the same file using [`generateImageMetadata`](/docs/app/api-reference/functions/generate-image-metadata).
> - You cannot generate a `favicon` icon. Use [`icon`](#icon) or a [favicon.ico](#favicon) file instead. > - You cannot generate a `favicon` icon. Use [`icon`](#icon) or a [favicon.ico](#favicon) file instead.
> - App icons are special Route Handlers that is cached by default unless it uses a [Dynamic API](/docs/app/building-your-application/caching#dynamic-apis) or [dynamic config](/docs/app/building-your-application/caching#segment-config-options) option. > - App icons are special Route Handlers that is cached by default unless it uses a [Dynamic API](/docs/app/deep-dive/caching#dynamic-apis) or [dynamic config](/docs/app/deep-dive/caching#segment-config-options) option.
### Props ### Props
......
...@@ -21,7 +21,7 @@ Add or generate a `manifest.(json|webmanifest)` file that matches the [Web Manif ...@@ -21,7 +21,7 @@ Add or generate a `manifest.(json|webmanifest)` file that matches the [Web Manif
Add a `manifest.js` or `manifest.ts` file that returns a [`Manifest` object](#manifest-object). Add a `manifest.js` or `manifest.ts` file that returns a [`Manifest` object](#manifest-object).
> Good to know: `manifest.js` is special Route Handlers that is cached by default unless it uses a [Dynamic API](/docs/app/building-your-application/caching#dynamic-apis) or [dynamic config](/docs/app/building-your-application/caching#segment-config-options) option. > Good to know: `manifest.js` is special Route Handlers that is cached by default unless it uses a [Dynamic API](/docs/app/deep-dive/caching#dynamic-apis) or [dynamic config](/docs/app/deep-dive/caching#segment-config-options) option.
```ts filename="app/manifest.ts" switcher ```ts filename="app/manifest.ts" switcher
import type { MetadataRoute } from 'next' import type { MetadataRoute } from 'next'
......
...@@ -90,7 +90,7 @@ Generate a route segment's shared image by creating an `opengraph-image` or `twi ...@@ -90,7 +90,7 @@ Generate a route segment's shared image by creating an `opengraph-image` or `twi
> >
> - By default, generated images are [**statically optimized**](/docs/app/building-your-application/rendering/server-components#static-rendering-default) (generated at build time and cached) unless they use [Dynamic APIs](/docs/app/building-your-application/rendering/server-components#server-rendering-strategies#dynamic-apis) or uncached data. > - By default, generated images are [**statically optimized**](/docs/app/building-your-application/rendering/server-components#static-rendering-default) (generated at build time and cached) unless they use [Dynamic APIs](/docs/app/building-your-application/rendering/server-components#server-rendering-strategies#dynamic-apis) or uncached data.
> - You can generate multiple Images in the same file using [`generateImageMetadata`](/docs/app/api-reference/functions/generate-image-metadata). > - You can generate multiple Images in the same file using [`generateImageMetadata`](/docs/app/api-reference/functions/generate-image-metadata).
> - `opengraph-image.js` and `twitter-image.js` are special Route Handlers that is cached by default unless it uses a [Dynamic API](/docs/app/building-your-application/caching#dynamic-apis) or [dynamic config](/docs/app/building-your-application/caching#segment-config-options) option. > - `opengraph-image.js` and `twitter-image.js` are special Route Handlers that is cached by default unless it uses a [Dynamic API](/docs/app/deep-dive/caching#dynamic-apis) or [dynamic config](/docs/app/deep-dive/caching#segment-config-options) option.
The easiest way to generate an image is to use the [ImageResponse](/docs/app/api-reference/functions/image-response) API from `next/og`. The easiest way to generate an image is to use the [ImageResponse](/docs/app/api-reference/functions/image-response) API from `next/og`.
......
...@@ -19,7 +19,7 @@ Sitemap: https://acme.com/sitemap.xml ...@@ -19,7 +19,7 @@ Sitemap: https://acme.com/sitemap.xml
Add a `robots.js` or `robots.ts` file that returns a [`Robots` object](#robots-object). Add a `robots.js` or `robots.ts` file that returns a [`Robots` object](#robots-object).
> **Good to know**: `robots.js` is a special Route Handlers that is cached by default unless it uses a [Dynamic API](/docs/app/building-your-application/caching#dynamic-apis) or [dynamic config](/docs/app/building-your-application/caching#segment-config-options) option. > **Good to know**: `robots.js` is a special Route Handlers that is cached by default unless it uses a [Dynamic API](/docs/app/deep-dive/caching#dynamic-apis) or [dynamic config](/docs/app/deep-dive/caching#segment-config-options) option.
```ts filename="app/robots.ts" switcher ```ts filename="app/robots.ts" switcher
import type { MetadataRoute } from 'next' import type { MetadataRoute } from 'next'
......
...@@ -41,7 +41,7 @@ For smaller applications, you can create a `sitemap.xml` file and place it in th ...@@ -41,7 +41,7 @@ For smaller applications, you can create a `sitemap.xml` file and place it in th
You can use the `sitemap.(js|ts)` file convention to programmatically **generate** a sitemap by exporting a default function that returns an array of URLs. If using TypeScript, a [`Sitemap`](#returns) type is available. You can use the `sitemap.(js|ts)` file convention to programmatically **generate** a sitemap by exporting a default function that returns an array of URLs. If using TypeScript, a [`Sitemap`](#returns) type is available.
> **Good to know**: `sitemap.js` is a special Route Handler that is cached by default unless it uses a [Dynamic API](/docs/app/building-your-application/caching#dynamic-apis) or [dynamic config](/docs/app/building-your-application/caching#segment-config-options) option. > **Good to know**: `sitemap.js` is a special Route Handler that is cached by default unless it uses a [Dynamic API](/docs/app/deep-dive/caching#dynamic-apis) or [dynamic config](/docs/app/deep-dive/caching#segment-config-options) option.
```ts filename="app/sitemap.ts" switcher ```ts filename="app/sitemap.ts" switcher
import type { MetadataRoute } from 'next' import type { MetadataRoute } from 'next'
......
...@@ -5,7 +5,7 @@ description: API reference for the extended fetch function. ...@@ -5,7 +5,7 @@ description: API reference for the extended fetch function.
Next.js extends the [Web `fetch()` API](https://developer.mozilla.org/docs/Web/API/Fetch_API) to allow each request on the server to set its own persistent caching and revalidation semantics. Next.js extends the [Web `fetch()` API](https://developer.mozilla.org/docs/Web/API/Fetch_API) to allow each request on the server to set its own persistent caching and revalidation semantics.
In the browser, the `cache` option indicates how a fetch request will interact with the _browser's_ HTTP cache. With this extension, `cache` indicates how a _server-side_ fetch request will interact with the framework's persistent [Data Cache](/docs/app/building-your-application/caching#data-cache). In the browser, the `cache` option indicates how a fetch request will interact with the _browser's_ HTTP cache. With this extension, `cache` indicates how a _server-side_ fetch request will interact with the framework's persistent [Data Cache](/docs/app/deep-dive/caching#data-cache).
You can call `fetch` with `async` and `await` directly within Server Components. You can call `fetch` with `async` and `await` directly within Server Components.
...@@ -43,7 +43,7 @@ Since Next.js extends the [Web `fetch()` API](https://developer.mozilla.org/docs ...@@ -43,7 +43,7 @@ Since Next.js extends the [Web `fetch()` API](https://developer.mozilla.org/docs
### `options.cache` ### `options.cache`
Configure how the request should interact with Next.js [Data Cache](/docs/app/building-your-application/caching#data-cache). Configure how the request should interact with Next.js [Data Cache](/docs/app/deep-dive/caching#data-cache).
```ts ```ts
fetch(`https://...`, { cache: 'force-cache' | 'no-store' }) fetch(`https://...`, { cache: 'force-cache' | 'no-store' })
......
...@@ -162,7 +162,7 @@ export default function Page({ params, searchParams }) {} ...@@ -162,7 +162,7 @@ export default function Page({ params, searchParams }) {}
> **Good to know**: > **Good to know**:
> >
> - If metadata doesn't depend on runtime information, it should be defined using the static [`metadata` object](#the-metadata-object) rather than `generateMetadata`. > - If metadata doesn't depend on runtime information, it should be defined using the static [`metadata` object](#the-metadata-object) rather than `generateMetadata`.
> - `fetch` requests are automatically [memoized](/docs/app/building-your-application/caching#request-memoization) for the same data across `generateMetadata`, `generateStaticParams`, Layouts, Pages, and Server Components. React [`cache` can be used](/docs/app/building-your-application/caching#react-cache-function) if `fetch` is unavailable. > - `fetch` requests are automatically [memoized](/docs/app/deep-dive/caching#request-memoization) for the same data across `generateMetadata`, `generateStaticParams`, Layouts, Pages, and Server Components. React [`cache` can be used](/docs/app/deep-dive/caching#react-cache-function) if `fetch` is unavailable.
> - `searchParams` are only available in `page.js` segments. > - `searchParams` are only available in `page.js` segments.
> - The [`redirect()`](/docs/app/api-reference/functions/redirect) and [`notFound()`](/docs/app/api-reference/functions/not-found) Next.js methods can also be used inside `generateMetadata`. > - The [`redirect()`](/docs/app/api-reference/functions/redirect) and [`notFound()`](/docs/app/api-reference/functions/not-found) Next.js methods can also be used inside `generateMetadata`.
......
...@@ -436,7 +436,7 @@ export default function Page({ params }) { ...@@ -436,7 +436,7 @@ export default function Page({ params }) {
} }
``` ```
> **Good to know**: `fetch` requests are automatically [memoized](/docs/app/building-your-application/caching#request-memoization) for the same data across all `generate`-prefixed functions, Layouts, Pages, and Server Components. React [`cache` can be used](/docs/app/building-your-application/caching#react-cache-function) if `fetch` is unavailable. > **Good to know**: `fetch` requests are automatically [memoized](/docs/app/deep-dive/caching#request-memoization) for the same data across all `generate`-prefixed functions, Layouts, Pages, and Server Components. React [`cache` can be used](/docs/app/deep-dive/caching#react-cache-function) if `fetch` is unavailable.
## Version History ## Version History
......
...@@ -3,13 +3,13 @@ title: revalidatePath ...@@ -3,13 +3,13 @@ title: revalidatePath
description: API Reference for the revalidatePath function. description: API Reference for the revalidatePath function.
--- ---
`revalidatePath` allows you to purge [cached data](/docs/app/building-your-application/caching) on-demand for a specific path. `revalidatePath` allows you to purge [cached data](/docs/app/deep-dive/caching) on-demand for a specific path.
> **Good to know**: > **Good to know**:
> >
> - `revalidatePath` only invalidates the cache when the included path is next visited. This means calling `revalidatePath` with a dynamic route segment will not immediately trigger many revalidations at once. The invalidation only happens when the path is next visited. > - `revalidatePath` only invalidates the cache when the included path is next visited. This means calling `revalidatePath` with a dynamic route segment will not immediately trigger many revalidations at once. The invalidation only happens when the path is next visited.
> - Currently, `revalidatePath` invalidates all the routes in the [client-side Router Cache](/docs/app/building-your-application/caching#client-side-router-cache) when used in a server action. This behavior is temporary and will be updated in the future to apply only to the specific path. > - Currently, `revalidatePath` invalidates all the routes in the [client-side Router Cache](/docs/app/deep-dive/caching#client-side-router-cache) when used in a server action. This behavior is temporary and will be updated in the future to apply only to the specific path.
> - Using `revalidatePath` invalidates **only the specific path** in the [server-side Route Cache](/docs/app/building-your-application/caching#full-route-cache). > - Using `revalidatePath` invalidates **only the specific path** in the [server-side Route Cache](/docs/app/deep-dive/caching#full-route-cache).
## Parameters ## Parameters
......
...@@ -3,7 +3,7 @@ title: revalidateTag ...@@ -3,7 +3,7 @@ title: revalidateTag
description: API Reference for the revalidateTag function. description: API Reference for the revalidateTag function.
--- ---
`revalidateTag` allows you to purge [cached data](/docs/app/building-your-application/caching) on-demand for a specific cache tag. `revalidateTag` allows you to purge [cached data](/docs/app/deep-dive/caching) on-demand for a specific cache tag.
> **Good to know**: > **Good to know**:
> >
......
...@@ -25,7 +25,7 @@ export default async function Component({ userID }) { ...@@ -25,7 +25,7 @@ export default async function Component({ userID }) {
> **Good to know**: > **Good to know**:
> >
> - Accessing dynamic data sources such as `headers` or `cookies` inside a cache scope is not supported. If you need this data inside a cached function use `headers` outside of the cached function and pass the required dynamic data in as an argument. > - Accessing dynamic data sources such as `headers` or `cookies` inside a cache scope is not supported. If you need this data inside a cached function use `headers` outside of the cached function and pass the required dynamic data in as an argument.
> - This API uses Next.js' built-in [Data Cache](/docs/app/building-your-application/caching#data-cache) to persist the result across requests and deployments. > - This API uses Next.js' built-in [Data Cache](/docs/app/deep-dive/caching#data-cache) to persist the result across requests and deployments.
> **Warning**: This API is unstable and may change in the future. We will provide migration documentation and codemods, if needed, as this API stabilizes. > **Warning**: This API is unstable and may change in the future. We will provide migration documentation and codemods, if needed, as this API stabilizes.
......
...@@ -394,7 +394,7 @@ However, you can set `Cache-Control` headers for other responses or data. ...@@ -394,7 +394,7 @@ However, you can set `Cache-Control` headers for other responses or data.
<AppOnly> <AppOnly>
Learn more about [caching](/docs/app/building-your-application/caching) with the App Router. Learn more about [caching](/docs/app/deep-dive/caching) with the App Router.
</AppOnly> </AppOnly>
......
...@@ -4,7 +4,7 @@ description: Learn how to override the invalidation time of the Client Router Ca ...@@ -4,7 +4,7 @@ description: Learn how to override the invalidation time of the Client Router Ca
version: experimental version: experimental
--- ---
`staleTimes` is an experimental feature that enables caching of page segments in the [client-side router cache](/docs/app/building-your-application/caching#client-side-router-cache). `staleTimes` is an experimental feature that enables caching of page segments in the [client-side router cache](/docs/app/deep-dive/caching#client-side-router-cache).
You can enable this experimental feature and provide custom revalidation times by setting the experimental `staleTimes` flag: You can enable this experimental feature and provide custom revalidation times by setting the experimental `staleTimes` flag:
...@@ -26,16 +26,16 @@ The `static` and `dynamic` properties correspond with the time period (in second ...@@ -26,16 +26,16 @@ The `static` and `dynamic` properties correspond with the time period (in second
- The `dynamic` property is used when the page is neither statically generated nor fully prefetched (e.g. with `prefetch={true}`). - The `dynamic` property is used when the page is neither statically generated nor fully prefetched (e.g. with `prefetch={true}`).
- Default: 0 seconds (not cached) - Default: 0 seconds (not cached)
- The `static` property is used for statically generated pages, or when the `prefetch` prop on `Link` is set to `true`, or when calling [`router.prefetch`](/docs/app/building-your-application/caching#routerprefetch). - The `static` property is used for statically generated pages, or when the `prefetch` prop on `Link` is set to `true`, or when calling [`router.prefetch`](/docs/app/deep-dive/caching#routerprefetch).
- Default: 5 minutes - Default: 5 minutes
> **Good to know:** > **Good to know:**
> >
> - [Loading boundaries](/docs/app/api-reference/file-conventions/loading) are considered reusable for the `static` period defined in this configuration. > - [Loading boundaries](/docs/app/api-reference/file-conventions/loading) are considered reusable for the `static` period defined in this configuration.
> - This doesn't affect [partial rendering](/docs/app/building-your-application/routing/linking-and-navigating#4-partial-rendering), **meaning shared layouts won't automatically be refetched on every navigation, only the page segment that changes.** > - This doesn't affect [partial rendering](/docs/app/building-your-application/routing/linking-and-navigating#4-partial-rendering), **meaning shared layouts won't automatically be refetched on every navigation, only the page segment that changes.**
> - This doesn't change [back/forward caching](/docs/app/building-your-application/caching#client-side-router-cache) behavior to prevent layout shift and to prevent losing the browser scroll position. > - This doesn't change [back/forward caching](/docs/app/deep-dive/caching#client-side-router-cache) behavior to prevent layout shift and to prevent losing the browser scroll position.
You can learn more about the Client Router Cache [here](/docs/app/building-your-application/caching#client-side-router-cache). You can learn more about the Client Router Cache [here](/docs/app/deep-dive/caching#client-side-router-cache).
### Version History ### Version History
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment