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
4 changes: 2 additions & 2 deletions packages/nextjs-cache-handler/src/handlers/redis-strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export default function createHandler({
return null;
}

const cacheValue = valueSerializer.deserialize(result);
const cacheValue = await valueSerializer.deserialize(result);

if (!cacheValue) {
return null;
Expand Down Expand Up @@ -254,7 +254,7 @@ export default function createHandler({
parseBuffersToStrings({ ...cacheHandlerValue, value: valueForStorage });
}

const serializedValue = valueSerializer.serialize({
const serializedValue = await valueSerializer.serialize({
...cacheHandlerValue,
value: valueForStorage,
});
Expand Down
12 changes: 10 additions & 2 deletions packages/nextjs-cache-handler/src/handlers/redis-strings.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import type { CacheHandlerValue } from "./cache-handler.types";
/**
* Pluggable wire-format codec for Redis string values (JSON, compression, encryption, etc.).
* Default behavior is JSON.stringify / JSON.parse (see `jsonCacheValueSerializer` export).
*
* Both methods may return a `Promise`, enabling non-blocking async codecs such as
* stream-based compression (`zlib.brotliCompress`) or encryption (`crypto.subtle`).
* Synchronous implementations continue to work unchanged — `await` on a plain value is a no-op.
*/
export type CacheValueSerializer = {
serialize(value: CacheHandlerValue): string;
deserialize(stored: string): CacheHandlerValue | null;
serialize(value: CacheHandlerValue): string | Promise<string>;
deserialize(stored: string): CacheHandlerValue | null | Promise<CacheHandlerValue | null>;
};

export type RedisCompliantCachedRouteValue = {
Expand Down Expand Up @@ -86,6 +90,10 @@ export type CreateRedisStringsHandlerOptions<
* Optional codec for values stored in Redis (`SET`/`GET`).
* Implement compression, encryption, or custom formats in your app; this package stays dependency-free.
*
* Both `serialize` and `deserialize` may return a `Promise`, enabling non-blocking async codecs
* (e.g. `zlib.brotliCompress` / `zlib.brotliDecompress`) that avoid blocking the Node.js event loop.
* Synchronous implementations continue to work unchanged.
*
* @default JSON.stringify / JSON.parse (same as previous releases)
*/
valueSerializer?: CacheValueSerializer;
Expand Down
Loading