Skip to content

Commit a64cc5b

Browse files
committed
3.2.0
1 parent 60f0c64 commit a64cc5b

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

README.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,13 @@ import createRedisHandler, {
266266
} from "@fortedigital/nextjs-cache-handler/redis-strings";
267267
```
268268

269-
**Example: gzip + base64**
269+
**Example: gzip**
270270

271271
Useful when cache entries are large text (RSC payloads, HTML). Uses Node’s built-in `zlib`; `gzipSync` / `gunzipSync` run on the server during cache reads and writes-profile if your traffic is very hot.
272272

273273
```js
274-
import { gzipSync, gunzipSync } from "node:zlib";
275274
import createRedisHandler from "@fortedigital/nextjs-cache-handler/redis-strings";
275+
import { gzipSync, gunzipSync } from "zlib";
276276

277277
const redisCacheHandler = createRedisHandler({
278278
client: redisClient,
@@ -289,6 +289,38 @@ const redisCacheHandler = createRedisHandler({
289289
});
290290
```
291291

292+
**Example: brotli**
293+
294+
Useful when cache entries are large text (RSC payloads, HTML). Uses Node’s built-in `zlib`; `brotliCompress` / `brotliDecompress` run on the server during cache reads and writes-profile if your traffic is very hot.
295+
296+
```js
297+
import createRedisHandler from "@fortedigital/nextjs-cache-handler/redis-strings";
298+
import { brotliCompress, brotliDecompress } from "zlib";
299+
import { promisify } from "util";
300+
301+
const brotliCompressAsync = promisify(brotliCompress);
302+
const brotliDecompressAsync = promisify(brotliDecompress);
303+
304+
const redisCacheHandler = createRedisHandler({
305+
client: redisClient,
306+
keyPrefix: "nextjs:",
307+
valueSerializer: {
308+
async serialize(value) {
309+
const compressed = await brotliCompressAsync(
310+
Buffer.from(JSON.stringify(value), "utf8"),
311+
);
312+
return compressed.toString("base64");
313+
},
314+
async deserialize(stored) {
315+
const decompressed = await brotliDecompressAsync(
316+
Buffer.from(stored, "base64"),
317+
);
318+
return JSON.parse(decompressed.toString("utf8"));
319+
},
320+
},
321+
});
322+
```
323+
292324
**Operational notes**
293325

294326
- Changing `valueSerializer` (or toggling compression) makes existing Redis keys unreadable until you flush those keys or run a migration; plan a key prefix bump or cache clear on deploy.

packages/nextjs-cache-handler/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"next",
1919
"redis"
2020
],
21-
"version": "3.1.0",
21+
"version": "3.2.0",
2222
"type": "module",
2323
"license": "MIT",
2424
"description": "Next.js cache handlers",

0 commit comments

Comments
 (0)