@leejpsd/nextjs-cache-handler 0.3.4 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +42 -0
- package/README.md +10 -3
- package/bin/cli.cjs +10 -0
- package/dist/cache-components/index.cjs +150 -4
- package/dist/cache-components/index.cjs.map +1 -1
- package/dist/cache-components/index.d.cts +1 -1
- package/dist/cache-components/index.d.ts +1 -1
- package/dist/cache-components/index.js +150 -4
- package/dist/cache-components/index.js.map +1 -1
- package/dist/cli/index.cjs +938 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/cli/index.d.cts +28 -0
- package/dist/cli/index.d.ts +28 -0
- package/dist/cli/index.js +928 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/incremental/index.cjs +81 -6
- package/dist/incremental/index.cjs.map +1 -1
- package/dist/incremental/index.d.cts +1 -1
- package/dist/incremental/index.d.ts +1 -1
- package/dist/incremental/index.js +81 -6
- package/dist/incremental/index.js.map +1 -1
- package/dist/index.cjs +157 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +157 -8
- package/dist/index.js.map +1 -1
- package/dist/ops/index.d.cts +1 -1
- package/dist/ops/index.d.ts +1 -1
- package/dist/otel/index.d.cts +1 -1
- package/dist/otel/index.d.ts +1 -1
- package/dist/seed/index.cjs +561 -0
- package/dist/seed/index.cjs.map +1 -0
- package/dist/seed/index.d.cts +53 -0
- package/dist/seed/index.d.ts +53 -0
- package/dist/seed/index.js +550 -0
- package/dist/seed/index.js.map +1 -0
- package/dist/shared/client/adapter-ioredis.cjs +40 -1
- package/dist/shared/client/adapter-ioredis.cjs.map +1 -1
- package/dist/shared/client/adapter-ioredis.d.cts +1 -1
- package/dist/shared/client/adapter-ioredis.d.ts +1 -1
- package/dist/shared/client/adapter-ioredis.js +40 -1
- package/dist/shared/client/adapter-ioredis.js.map +1 -1
- package/dist/shared/client/adapter-redis.cjs +34 -1
- package/dist/shared/client/adapter-redis.cjs.map +1 -1
- package/dist/shared/client/adapter-redis.d.cts +1 -1
- package/dist/shared/client/adapter-redis.d.ts +1 -1
- package/dist/shared/client/adapter-redis.js +34 -1
- package/dist/shared/client/adapter-redis.js.map +1 -1
- package/dist/{types-Bl-rkLKX.d.cts → types-C1vJ_sED.d.cts} +25 -1
- package/dist/{types-Bl-rkLKX.d.ts → types-C1vJ_sED.d.ts} +25 -1
- package/package.json +22 -2
- package/setup-instructions/setup.md +31 -9
- package/skills/nextjs-redis-cache/SKILL.md +15 -0
|
@@ -22,7 +22,9 @@ The workflow includes:
|
|
|
22
22
|
`redis://127.0.0.1:6379` for local verification and tell the user to set
|
|
23
23
|
`REDIS_URL` in their deployment environment.
|
|
24
24
|
- deployment_version_source (optional): how the app derives
|
|
25
|
-
`DEPLOYMENT_VERSION` (git SHA, CI build id). Default: `git rev-parse
|
|
25
|
+
`DEPLOYMENT_VERSION` (git SHA, CI build id). Default: `git rev-parse
|
|
26
|
+
--short HEAD`; if the directory is not a git repo, fall back to a fixed
|
|
27
|
+
value the user chooses (any stable per-deploy string works).
|
|
26
28
|
|
|
27
29
|
Constraints:
|
|
28
30
|
|
|
@@ -30,7 +32,8 @@ Constraints:
|
|
|
30
32
|
user Vercel's managed cache already covers them, and stop.
|
|
31
33
|
- You MUST detect the Next.js version before choosing which handlers to wire.
|
|
32
34
|
- You MUST show the `next.config` diff and get explicit approval before
|
|
33
|
-
writing it — this file frequently contains user customizations
|
|
35
|
+
writing it — this file frequently contains user customizations — unless
|
|
36
|
+
the user has already given blanket approval for changes in this project.
|
|
34
37
|
- You MUST NOT print or commit secrets (Redis passwords, URLs with auth).
|
|
35
38
|
- You MUST install version >= 0.3.3 (earlier versions have an incomplete
|
|
36
39
|
soft-invalidation path).
|
|
@@ -94,15 +97,25 @@ user's infrastructure requires them (Cluster additionally needs
|
|
|
94
97
|
|
|
95
98
|
### Step 4: Patch next.config (approval required)
|
|
96
99
|
|
|
97
|
-
|
|
100
|
+
If no `next.config.(js|ts|mjs)` exists, CREATE `next.config.js` with just
|
|
101
|
+
these keys. If one exists, merge the keys into it — do not replace the
|
|
102
|
+
file. Show the diff and get approval first, unless the user already gave
|
|
103
|
+
blanket approval for this project's files:
|
|
98
104
|
|
|
99
105
|
```ts
|
|
100
106
|
cacheHandler: require.resolve("./cache-incremental.cjs"),
|
|
101
107
|
cacheHandlers: { default: require.resolve("./cache-components.cjs") }, // Next 16 only
|
|
102
|
-
cacheComponents: true, // Next 16 only —
|
|
108
|
+
cacheComponents: true, // Next 16 only — see the warning below before enabling
|
|
103
109
|
cacheMaxMemorySize: 0, // required for multi-instance correctness
|
|
104
110
|
```
|
|
105
111
|
|
|
112
|
+
**`cacheComponents: true` decision rule**: enabling it is a MODE SWITCH, not
|
|
113
|
+
a free feature — it is incompatible with route segment configs like
|
|
114
|
+
`export const revalidate` / `export const dynamic` and will FAIL THE BUILD
|
|
115
|
+
of apps that use them. Enable it only when the app already uses (or is
|
|
116
|
+
migrating to) `'use cache'`. When in doubt, wire `cacheHandlers` but leave
|
|
117
|
+
`cacheComponents` off and tell the user how to enable it later.
|
|
118
|
+
|
|
106
119
|
Show the diff, get approval, then write.
|
|
107
120
|
|
|
108
121
|
**Error handling:**
|
|
@@ -125,16 +138,25 @@ Append both to `.env.example` if the project has one.
|
|
|
125
138
|
### Step 6: Verify
|
|
126
139
|
|
|
127
140
|
With a local Redis (`docker run -d -p 6379:6379 redis:7-alpine` or a native
|
|
128
|
-
`redis-server`), run:
|
|
141
|
+
`redis-server`), run (pick a free port explicitly — do not assume 3000):
|
|
129
142
|
|
|
130
143
|
```bash
|
|
131
144
|
REDIS_URL=redis://127.0.0.1:6379 DEPLOYMENT_VERSION=setup-verify npm run build
|
|
132
|
-
REDIS_URL=redis://127.0.0.1:6379 DEPLOYMENT_VERSION=setup-verify npm run start &
|
|
145
|
+
REDIS_URL=redis://127.0.0.1:6379 DEPLOYMENT_VERSION=setup-verify npm run start -- -p 3777 &
|
|
146
|
+
# wait for readiness before curling:
|
|
147
|
+
for i in $(seq 1 30); do curl -sf http://127.0.0.1:3777/ >/dev/null && break; sleep 1; done
|
|
133
148
|
```
|
|
134
149
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
150
|
+
Check the `x-nextjs-cache` header on an ISR/static page. **Two valid
|
|
151
|
+
outcomes**: build-time-prerendered pages are often served as `HIT` from the
|
|
152
|
+
very first request; on-demand pages show `MISS` then `HIT`. Either way,
|
|
153
|
+
confirm keys exist with `redis-cli --scan --pattern 'next-incremental:*'`
|
|
154
|
+
(never use `KEYS` — it blocks Redis).
|
|
155
|
+
|
|
156
|
+
The strongest proof is a full round-trip: delete the page's entry key with
|
|
157
|
+
the server running, then request twice — expect `MISS` then `HIT` and the
|
|
158
|
+
key to REAPPEAR in Redis (proves both read and write paths). Kill the
|
|
159
|
+
server afterwards and verify the port is free.
|
|
138
160
|
|
|
139
161
|
**Error handling:**
|
|
140
162
|
|
|
@@ -109,12 +109,27 @@ Facts that prevent misdiagnosis:
|
|
|
109
109
|
| `abortTimeoutMs` | 1500 | Per-op Redis deadline; timeouts degrade to miss |
|
|
110
110
|
| `hashTag: true` | off | REQUIRED on Redis Cluster |
|
|
111
111
|
| `onMetric` | — | Wire `createOtelMetricEmitter()` from `@leejpsd/nextjs-cache-handler/otel` |
|
|
112
|
+
| `tagPubSub: true` | off | 0.4+: push-based cross-instance invalidation (~3ms vs seconds); polling stays as safety net; not on Cluster |
|
|
112
113
|
|
|
113
114
|
Reliability built in (0.3+): reconnect with exponential backoff (1s→30s cap),
|
|
114
115
|
bounded memory fallback, per-op timeouts. A Redis outage degrades to
|
|
115
116
|
in-memory serving; reconnection is automatic (validated with a live
|
|
116
117
|
ElastiCache reboot drill: 2550 requests, zero 5xx).
|
|
117
118
|
|
|
119
|
+
### 0.4+ deployment accelerators
|
|
120
|
+
|
|
121
|
+
- **Seed the cache at deploy time** so a fresh deployment's first requests
|
|
122
|
+
are HITs instead of a regeneration stampede:
|
|
123
|
+
`REDIS_URL=... DEPLOYMENT_VERSION=<deploy-id> npx nextjs-cache-handler seed`
|
|
124
|
+
(run after `next build`, e.g. a Docker entrypoint step; NX semantics —
|
|
125
|
+
never overwrites live entries).
|
|
126
|
+
- **`npx nextjs-cache-handler init --yes`** wires everything above
|
|
127
|
+
automatically; **`npx nextjs-cache-handler doctor`** is the first command
|
|
128
|
+
to run when debugging connectivity or key-layout issues.
|
|
129
|
+
- **MCP server** for cache operations from your agent:
|
|
130
|
+
`@leejpsd/nextjs-cache-handler-mcp` (cache_health, tag_state,
|
|
131
|
+
invalidate_tag dry-run, …).
|
|
132
|
+
|
|
118
133
|
## 6. Production checklist
|
|
119
134
|
|
|
120
135
|
- [ ] `DEPLOYMENT_VERSION` injected at runtime (runner stage in Docker)
|