From 8a0e0f202baf3e038a7cde6f24618a9da34bf7d9 Mon Sep 17 00:00:00 2001 From: Zenith Date: Mon, 22 Apr 2024 11:02:22 -0700 Subject: [PATCH] Tell serialize fn if it's being used on arguments --- src/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index e278572..76142e3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,11 +18,11 @@ export interface MemoizerOptions { noBody: boolean throwError: boolean retryOnInvalidCache: boolean - serialize: (val: unknown) => string + serialize: (val: unknown, isArgs: boolean) => string deserialize: (val: string) => unknown } -function serialize(val: unknown) { +function serialize(val: unknown, _isArgs: boolean) { const circRefColl: unknown[] = [] return JSON.stringify(val, function (name, value) { if (typeof value === 'function') { @@ -60,7 +60,7 @@ export function getCacheFilePath( fnStr = options.astBody ? JSON.stringify(fnStr) : fnStr } - const argsStr = options.serialize(args) + const argsStr = options.serialize(args, true) const hash = crypto .createHash('md5') .update(fnStr + argsStr + salt) @@ -127,7 +127,7 @@ async function writeResult( let resultString if ((r && typeof r === 'object') || typeof r === 'string') { resultObj = { data: r } - resultString = optExt.serialize(resultObj) + resultString = optExt.serialize(resultObj, false) } else { resultString = '{"data":' + r + '}' }