From 8cad0cce25437a93eadd0f5aa3bcbac27c8d6c1d Mon Sep 17 00:00:00 2001 From: leejpsd Date: Fri, 4 Dec 2026 00:05:38 +0900 Subject: [PATCH] docs: cacheMaxMemorySize: 0 is optional, not a multi-instance requirement With a custom cacheHandler, Next keeps no in-memory ISR cache of its own: the value is passed to the handler's constructor (incremental-cache/index.js) and this handler never reads it. It only sizes Next's built-in 'use cache' store (use-cache/handlers.js initializeCacheHandlers), which cacheHandlers.default replaces. README, AGENTS.md, the skill, setup.md and the init output said it was required for multi-instance correctness; they now say it is optional and why. The troubleshooting row that listed it as a cause of cross-instance misses drops that cause. --- .changeset/cache-max-memory-size-wording.md | 5 +++++ AGENTS.md | 5 +++-- README.md | 9 ++++++--- setup-instructions/setup.md | 2 +- skills/nextjs-redis-cache/SKILL.md | 6 +++--- src/cli/index.ts | 2 +- 6 files changed, 19 insertions(+), 10 deletions(-) create mode 100644 .changeset/cache-max-memory-size-wording.md diff --git a/.changeset/cache-max-memory-size-wording.md b/.changeset/cache-max-memory-size-wording.md new file mode 100644 index 0000000..c3d4549 --- /dev/null +++ b/.changeset/cache-max-memory-size-wording.md @@ -0,0 +1,5 @@ +--- +"@leejpsd/nextjs-cache-handler": patch +--- + +Docs and `init` output no longer call `cacheMaxMemorySize: 0` required for multi-instance correctness. With a custom `cacheHandler`, Next keeps no in-memory ISR cache of its own: the value is passed to the handler's constructor (this handler ignores it) and only sizes Next's built-in `'use cache'` store, which `cacheHandlers.default` replaces. Keeping `0` is harmless; it was never what made multi-instance reads consistent. diff --git a/AGENTS.md b/AGENTS.md index e83dc65..d57e0df 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -15,8 +15,9 @@ https://raw.githubusercontent.com/leejpsd/nextjs-cache-handler/main/setup-instru stale serve + background re-render, cross-instance convergence in ~1-2s. Brief stale content is BY DESIGN — not a bug. `updateTag(tag)` is HARD = delete + blocking regeneration. Requires version >= 0.3.3. -2. `cacheMaxMemorySize: 0` in next.config is mandatory for multi-instance - correctness. Do not remove it. +2. `cacheMaxMemorySize: 0` in next.config is optional, not a correctness + requirement: with a custom `cacheHandler` Next keeps no ISR memory cache + of its own. Keep it if present; do not call it mandatory. 3. `DEPLOYMENT_VERSION` env must exist at RUNTIME (Docker runner stage). Missing → cross-deploy cache bleed / static chunk 404s. 4. Redis Cluster needs `hashTag: true`; TLS via `rediss://` URLs. diff --git a/README.md b/README.md index 34d05e2..3b8e202 100644 --- a/README.md +++ b/README.md @@ -175,7 +175,7 @@ const nextConfig: NextConfig = { cacheComponents: true, deploymentId: process.env.DEPLOYMENT_VERSION, generateBuildId: async () => process.env.DEPLOYMENT_VERSION ?? "dev-build", - cacheMaxMemorySize: 0, // delegate everything to the Redis handler + cacheMaxMemorySize: 0, // optional — no effect on the ISR path; see Production checklist cacheHandler: enabled ? require.resolve("./cache-incremental.cjs") : undefined, cacheHandlers: enabled ? { default: require.resolve("./cache-components.cjs") } : {}, }; @@ -249,8 +249,11 @@ Full reference: [`docs/api.md`](./docs/api.md). prefixed with this so old prerender HTML can't bleed across deploys. For Docker, set `ENV DEPLOYMENT_VERSION=...` in your **runner** stage, not just the builder. (See [`docs/build-phase.md`](./docs/build-phase.md).) -- [ ] **`cacheMaxMemorySize: 0`** — turn off Next's local LRU so multi-instance - reads always hit Redis (or the explicit memory fallback). +- [ ] **`cacheMaxMemorySize: 0`** — optional. With a custom `cacheHandler`, + Next keeps no in-memory ISR cache of its own: the value is passed to the + handler's constructor, and this handler ignores it. It only sizes Next's + built-in `'use cache'` store, which `cacheHandlers.default` replaces. + Next's self-hosting docs still suggest `0`; keeping it is harmless. - [ ] **`outputFileTracingRoot` pinned** — required for `output: "standalone"` to avoid static-chunk-404 issues during a deploy. - [ ] **`abortTimeoutMs: 1500`** (default) — protects against a stuck Redis diff --git a/setup-instructions/setup.md b/setup-instructions/setup.md index d1544a6..4ba029f 100644 --- a/setup-instructions/setup.md +++ b/setup-instructions/setup.md @@ -106,7 +106,7 @@ blanket approval for this project's files: cacheHandler: require.resolve("./cache-incremental.cjs"), cacheHandlers: { default: require.resolve("./cache-components.cjs") }, // Next 16 only cacheComponents: true, // Next 16 only — see the warning below before enabling -cacheMaxMemorySize: 0, // required for multi-instance correctness +cacheMaxMemorySize: 0, // optional: no effect on the ISR path; sizes Next's built-in 'use cache' store only ``` **`cacheComponents: true` decision rule**: enabling it is a MODE SWITCH, not diff --git a/skills/nextjs-redis-cache/SKILL.md b/skills/nextjs-redis-cache/SKILL.md index 93c3931..3e936cb 100644 --- a/skills/nextjs-redis-cache/SKILL.md +++ b/skills/nextjs-redis-cache/SKILL.md @@ -58,7 +58,7 @@ const nextConfig = { cacheComponents: true, // Next 16 only cacheHandler: require.resolve("./cache-incremental.cjs"), cacheHandlers: { default: require.resolve("./cache-components.cjs") }, // Next 16 only - cacheMaxMemorySize: 0, // REQUIRED: disable Next's local LRU so multi-instance reads hit Redis + cacheMaxMemorySize: 0, // optional: Next keeps no ISR memory cache with a custom cacheHandler; this only sizes the built-in 'use cache' store }; ``` @@ -144,7 +144,7 @@ ElastiCache reboot drill: 2550 requests, zero 5xx). ## 6. Production checklist - [ ] `DEPLOYMENT_VERSION` injected at runtime (runner stage in Docker) -- [ ] `cacheMaxMemorySize: 0` in next.config +- [ ] `cacheMaxMemorySize: 0` in next.config (optional; see §2) - [ ] `output: "standalone"` + pinned `outputFileTracingRoot` - [ ] Cluster → `hashTag: true`; managed Redis TLS → `rediss://` - [ ] Redis `maxmemory-policy`: `allkeys-lru` (bounded) or `noeviction` @@ -159,7 +159,7 @@ ElastiCache reboot drill: 2550 requests, zero 5xx). | Page content never updates after `revalidateTag(tag, "max")` | version < 0.3.3 | Upgrade | | Static chunk 404s right after a deploy | `DEPLOYMENT_VERSION` missing in runner stage → old HTML served from shared Redis | Set it; entries are namespaced per deploy | | `CROSSSLOT` errors | Redis Cluster without `hashTag: true` | Set the flag | -| Cache misses on every request across instances | `cacheMaxMemorySize` not 0, or different `keyPrefix`/namespace per instance | Align config; verify with `redis-cli KEYS 'next-*'` | +| Cache misses on every request across instances | Different `keyPrefix`/namespace per instance (e.g. `DEPLOYMENT_VERSION` set on only some instances) | Align config; verify with `redis-cli KEYS 'next-*'` | | Works locally, memory-only in prod | Redis URL/security group wrong; check logs for `redis.connect.failed` | Connectivity; the app stays up on fallback by design | Key layout for redis-cli debugging: diff --git a/src/cli/index.ts b/src/cli/index.ts index 8174b26..1cc70a5 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -179,7 +179,7 @@ export async function init(ctx: Ctx): Promise { `cacheComponents: true,`, ] : []), - `cacheMaxMemorySize: 0, // required for multi-instance correctness`, + `cacheMaxMemorySize: 0, // optional: no effect on the ISR path with this handler`, ]; if (!cfg) { log(`${WARN} no next.config found — create one with:`);