You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default, the handler stores each entry as a JSON string (`JSON.stringify` / `JSON.parse`), matching earlier releases. You can plug in your own wire format to shrink payloads (compression), add encryption, or use another encoding-this package does not ship extra codecs so your dependencies stay minimal.
251
+
252
+
**Contract**
253
+
254
+
-`serialize(value)` receives the full cache object Next.js passes in (metadata such as `tags`, `lastModified`, `lifespan`, plus the nested `value` payload). It must return a string suitable for Redis `SET`.
255
+
-`deserialize(stored)` receives that string from Redis `GET`. Return a parsed object compatible with the handler, or `null` to treat the key as a miss (stale entries are removed).
256
+
257
+
The handler normalizes `Buffer` fields inside the payload to strings before `serialize`, and restores buffers after `deserialize`, so a plain `JSON.stringify` / `JSON.parse` round trip remains valid.
258
+
259
+
**Default export for reuse**
260
+
261
+
You can import the built-in serializer if you want to wrap or compare behavior:
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.
- 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.
295
+
- Tag maps and TTL sidecar hashes are still stored as JSON by the handler; only the main entry value uses your serializer.
0 commit comments