@soundxyz/fine-grained-cache
Advanced tools
Comparing version 2.4.0 to 3.0.0
@@ -101,3 +101,3 @@ import type { Redis } from "ioredis"; | ||
}): { | ||
getCached: <T>(cb: CachedCallback<T>, { timedInvalidation, ttl, keys, maxExpectedTime, retryLockTime, checkShortMemoryCache, useSuperjson, useRedlock, forceUpdate, }: { | ||
getCached: <T>(cb: CachedCallback<T>, { timedInvalidation, ttl, keys, maxExpectedTime, retryLockTime, checkShortMemoryCache, useRedlock, forceUpdate, }: { | ||
timedInvalidation?: Date | (() => Date | Promise<Date>) | undefined; | ||
@@ -117,6 +117,2 @@ ttl: StringValue | "Infinity"; | ||
/** | ||
* @default true | ||
*/ | ||
useSuperjson?: boolean | undefined; | ||
/** | ||
* @default false | ||
@@ -134,12 +130,10 @@ */ | ||
invalidateCache: (keys_0: string, ...keys_1: (string | number)[]) => Promise<void>; | ||
setCache: <T_1 = unknown>({ populateMemoryCache, ttl, keys, useSuperjson, value, }: { | ||
setCache: <T_1 = unknown>({ populateMemoryCache, ttl, keys, value, }: { | ||
populateMemoryCache: boolean; | ||
ttl: StringValue | "Infinity"; | ||
keys: string | [string, ...(string | number)[]]; | ||
useSuperjson: boolean; | ||
value: T_1; | ||
}) => Promise<void>; | ||
readCache: <T_2 = unknown>({ keys, useSuperjson, }: { | ||
readCache: <T_2 = unknown>({ keys }: { | ||
keys: string | [string, ...(string | number)[]]; | ||
useSuperjson: boolean; | ||
}) => Promise<{ | ||
@@ -146,0 +140,0 @@ readonly found: false; |
@@ -248,3 +248,3 @@ 'use strict'; | ||
} | ||
async function getRedisCacheValue(key, useSuperjson, checkShortMemoryCache) { | ||
async function getRedisCacheValue(key, checkShortMemoryCache) { | ||
const tracing = enabledLogEvents?.REDIS_GET || enabledLogEvents?.REDIS_GET_TIMED_OUT ? getTracing() : null; | ||
@@ -285,3 +285,3 @@ let timedOut = void 0; | ||
try { | ||
parsedRedisValue = useSuperjson ? superjson__default["default"].parse(redisValue) : JSON.parse(redisValue); | ||
parsedRedisValue = superjson__default["default"].parse(redisValue); | ||
} catch (err) { | ||
@@ -307,3 +307,2 @@ onError(new Error(`Unexpected JSON string for ${key}`)); | ||
checkShortMemoryCache = defaultUseMemoryCache, | ||
useSuperjson = true, | ||
useRedlock = useRedlockByDefault, | ||
@@ -329,7 +328,3 @@ forceUpdate = false | ||
return getNewValue(); | ||
const redisValue = await getRedisCacheValue( | ||
key, | ||
useSuperjson, | ||
checkShortMemoryCache | ||
); | ||
const redisValue = await getRedisCacheValue(key, checkShortMemoryCache); | ||
if (redisValue !== NotFoundSymbol) | ||
@@ -377,3 +372,2 @@ return redisValue; | ||
key, | ||
useSuperjson, | ||
checkShortMemoryCache | ||
@@ -423,3 +417,3 @@ ); | ||
expirySeconds = timedInvalidationDate && timedInvalidationDate.getTime() > Date.now() ? utils.getRemainingSeconds(timedInvalidationDate) : ttlSeconds; | ||
const stringifiedValue = useSuperjson ? superjson__default["default"].stringify(newValue) : JSON.stringify(newValue); | ||
const stringifiedValue = superjson__default["default"].stringify(newValue); | ||
if (expirySeconds > 0) { | ||
@@ -520,3 +514,2 @@ if (pipelineRedisSET) { | ||
keys, | ||
useSuperjson, | ||
value | ||
@@ -526,3 +519,3 @@ }) { | ||
const expirySeconds = ttl === "Infinity" ? -1 : getExpirySeconds(ttl); | ||
const stringifiedValue = useSuperjson ? superjson__default["default"].stringify(value) : JSON.stringify(value); | ||
const stringifiedValue = superjson__default["default"].stringify(value); | ||
if (expirySeconds > 0) { | ||
@@ -571,8 +564,5 @@ if (populateMemoryCache) | ||
} | ||
function readCache({ | ||
keys, | ||
useSuperjson | ||
}) { | ||
function readCache({ keys }) { | ||
const key = generateCacheKey(keys); | ||
return getRedisCacheValue(key, useSuperjson, false).then((value) => { | ||
return getRedisCacheValue(key, false).then((value) => { | ||
if (value === NotFoundSymbol) { | ||
@@ -579,0 +569,0 @@ return { |
{ | ||
"name": "@soundxyz/fine-grained-cache", | ||
"version": "2.4.0", | ||
"version": "3.0.0", | ||
"description": "Fine-grained cache helper using redis", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
49829
1419