File tree Expand file tree Collapse file tree 3 files changed +27
-0
lines changed
Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -200,6 +200,27 @@ Options:
200200 });
201201 ` ` `
202202
203+ - ` transformer` : (optional) the transformer to used to serialize and deserialize the cache entries . It must be an object
204+ with the following methods:
205+
206+ - ` serialize` : a function that receives the result of the original function and returns a serializable object.
207+ - `deserialize`: a function that receives the serialized object and returns the original result.
208+
209+ - Default is `undefined`, so the default transformer is used.
210+
211+ Example
212+
213+ ```js
214+ import superjson from "superjson";
215+
216+ createPrismaRedisCache ({
217+ transformer: {
218+ serialize : (result ) => superjson .serialize (result),
219+ deserialize : (serialized ) => superjson .deserialize (serialized),
220+ },
221+ });
222+ ```
223+
203224## Debugging
204225
205226You can pass functions for `onMiss`, `onHit`, `onError` and `onDedupe` to `createPrismaRedisCache` which can then be
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ export const createPrismaRedisCache = ({
2424 cacheTime = DEFAULT_CACHE_TIME ,
2525 excludeModels = [ ] ,
2626 excludeMethods = [ ] ,
27+ transformer,
2728} : CreatePrismaRedisCache ) => {
2829 // Default options for "async-cache-dedupe"
2930 const cacheOptions = {
@@ -33,6 +34,7 @@ export const createPrismaRedisCache = ({
3334 onMiss,
3435 storage,
3536 ttl : cacheTime ,
37+ transformer,
3638 } ;
3739
3840 const cache : any = createCache ( cacheOptions ) ;
Original file line number Diff line number Diff line change @@ -85,4 +85,8 @@ export type CreatePrismaRedisCache = {
8585 onHit ?: ( key : string ) => void ;
8686 onMiss ?: ( key : string ) => void ;
8787 onDedupe ?: ( key : string ) => void ;
88+ transformer ?: {
89+ serialize : ( data : any ) => any ;
90+ deserialize : ( data : any ) => any ;
91+ } ;
8892} ;
You can’t perform that action at this time.
0 commit comments