Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cache-max-memory-size-wording.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 3 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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") } : {},
};
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup-instructions/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions skills/nextjs-redis-cache/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
```

Expand Down Expand Up @@ -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`
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export async function init(ctx: Ctx): Promise<number> {
`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:`);
Expand Down
Loading