From 5f3f94e443a1395ad97fbbe2016a377a36f98c42 Mon Sep 17 00:00:00 2001 From: Lee Robinson Date: Wed, 27 Apr 2022 11:54:01 -0500 Subject: [PATCH 1/3] Add docs on self-hosted ISR persisting across pods. --- .../incremental-static-regeneration.md | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/basic-features/data-fetching/incremental-static-regeneration.md b/docs/basic-features/data-fetching/incremental-static-regeneration.md index fa0a1b350e8d5..87ed18339e1e2 100644 --- a/docs/basic-features/data-fetching/incremental-static-regeneration.md +++ b/docs/basic-features/data-fetching/incremental-static-regeneration.md @@ -171,6 +171,29 @@ export async function getStaticProps() { } ``` +## Self-hosting ISR + +Incremental Static Regeneration (ISR) works on [self-hosted Next.js sites](/docs/deployment.md#self-hosting) out of the box when you use `next start`. + +You can use this approach when deploying to container orchestrators such as [Kubernetes](https://kubernetes.io/) or [HashiCorp Nomad](https://www.nomadproject.io/). By default, generated assets will be stored in-memory on each pod. This means that each pod will have its own copy of the static files. State data maybe shown until that specific pod is hit by a request. + +To ensure consistenly across all pods, you can disable in-memory caching. This will inform the Next.js server to only leverage storing assests generated by ISR in the file system. + +You can use a shared network mount in your Kubernetes pods (or similar setup) to reuse the same file-system cache between different containers. By sharing the same mount, the `.next` folder which contains the `next/image` cache will also be shared and re-used. + +To disable in-memory caching, set `isrMemoryCacheSize` to `0` in your `next.config.js` file: + +```js +module.exports = { + experimental: { + // Defaults to 50MB + isrMemoryCacheSize: 0, + }, +} +``` + +> **Note:** You might need to consider a race condition between multiple pods trying to update the cache at the same time, depending on how your shared mount is configured. + ## Related For more information on what to do next, we recommend the following sections: From cba46c4aba97a4e1fa98df2bdbe1d220e6098fad Mon Sep 17 00:00:00 2001 From: Lee Robinson Date: Wed, 27 Apr 2022 17:43:11 -0500 Subject: [PATCH 2/3] Update docs/basic-features/data-fetching/incremental-static-regeneration.md Co-authored-by: JJ Kasper --- .../data-fetching/incremental-static-regeneration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/basic-features/data-fetching/incremental-static-regeneration.md b/docs/basic-features/data-fetching/incremental-static-regeneration.md index 87ed18339e1e2..24e0354d69924 100644 --- a/docs/basic-features/data-fetching/incremental-static-regeneration.md +++ b/docs/basic-features/data-fetching/incremental-static-regeneration.md @@ -177,7 +177,7 @@ Incremental Static Regeneration (ISR) works on [self-hosted Next.js sites](/docs You can use this approach when deploying to container orchestrators such as [Kubernetes](https://kubernetes.io/) or [HashiCorp Nomad](https://www.nomadproject.io/). By default, generated assets will be stored in-memory on each pod. This means that each pod will have its own copy of the static files. State data maybe shown until that specific pod is hit by a request. -To ensure consistenly across all pods, you can disable in-memory caching. This will inform the Next.js server to only leverage storing assests generated by ISR in the file system. +To ensure consistency across all pods, you can disable in-memory caching. This will inform the Next.js server to only leverage assets generated by ISR in the file system. You can use a shared network mount in your Kubernetes pods (or similar setup) to reuse the same file-system cache between different containers. By sharing the same mount, the `.next` folder which contains the `next/image` cache will also be shared and re-used. From 561d3e67312817fe99b791a1a7bd01931780fa0a Mon Sep 17 00:00:00 2001 From: Lee Robinson Date: Wed, 27 Apr 2022 17:43:22 -0500 Subject: [PATCH 3/3] Update docs/basic-features/data-fetching/incremental-static-regeneration.md Co-authored-by: JJ Kasper --- .../data-fetching/incremental-static-regeneration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/basic-features/data-fetching/incremental-static-regeneration.md b/docs/basic-features/data-fetching/incremental-static-regeneration.md index 24e0354d69924..85478a77556a4 100644 --- a/docs/basic-features/data-fetching/incremental-static-regeneration.md +++ b/docs/basic-features/data-fetching/incremental-static-regeneration.md @@ -175,7 +175,7 @@ export async function getStaticProps() { Incremental Static Regeneration (ISR) works on [self-hosted Next.js sites](/docs/deployment.md#self-hosting) out of the box when you use `next start`. -You can use this approach when deploying to container orchestrators such as [Kubernetes](https://kubernetes.io/) or [HashiCorp Nomad](https://www.nomadproject.io/). By default, generated assets will be stored in-memory on each pod. This means that each pod will have its own copy of the static files. State data maybe shown until that specific pod is hit by a request. +You can use this approach when deploying to container orchestrators such as [Kubernetes](https://kubernetes.io/) or [HashiCorp Nomad](https://www.nomadproject.io/). By default, generated assets will be stored in-memory on each pod. This means that each pod will have its own copy of the static files. Stale data may be shown until that specific pod is hit by a request. To ensure consistency across all pods, you can disable in-memory caching. This will inform the Next.js server to only leverage assets generated by ISR in the file system.