@soundxyz/fine-grained-cache
Advanced tools
Comparing version 2.1.1 to 2.2.0
@@ -45,3 +45,3 @@ import type { Redis } from "ioredis"; | ||
}; | ||
export declare type LoggedEvents = Partial<Record<Events, string | boolean | null>>; | ||
export declare type LoggedEvents = Partial<Record<Events, string | boolean | null | ((args: LogEventArgs) => void)>>; | ||
export declare function FineGrainedCache({ redis, redLock: redLockConfig, keyPrefix, memoryCache, onError, logEvents, GETRedisTimeout, pipelineRedisGET, pipelineRedisSET, defaultUseMemoryCache, awaitRedisSet, }: { | ||
@@ -65,4 +65,7 @@ redis: Redis; | ||
logEvents?: { | ||
log: (args: LogEventArgs) => void; | ||
events: LoggedEvents; | ||
/** | ||
* @default console.log | ||
*/ | ||
log?: (args: LogEventArgs) => void; | ||
}; | ||
@@ -69,0 +72,0 @@ /** |
@@ -50,2 +50,5 @@ 'use strict'; | ||
}; | ||
function defaultLog({ message }) { | ||
console.log(message); | ||
} | ||
function FineGrainedCache({ | ||
@@ -77,7 +80,7 @@ redis, | ||
const logMessage = logEvents ? function logMessage2(code, params) { | ||
let codeValue = logEvents.events[code]; | ||
if (!codeValue) | ||
const eventValue = logEvents.events[code]; | ||
if (!eventValue) | ||
return; | ||
if (typeof codeValue !== "string") | ||
codeValue = Events[code]; | ||
const log = typeof eventValue === "function" ? eventValue : logEvents.log || defaultLog; | ||
const codeMessageValue = typeof eventValue === "string" ? eventValue : code; | ||
let paramsString = ""; | ||
@@ -92,5 +95,5 @@ for (const key in params) { | ||
} | ||
logEvents.log({ | ||
log({ | ||
code, | ||
message: `[${codeValue}]${paramsString}`, | ||
message: `[${codeMessageValue}]${paramsString}`, | ||
params | ||
@@ -387,3 +390,3 @@ }); | ||
if (expirySeconds > 0) { | ||
if (pipelineRedisSET != null) { | ||
if (pipelineRedisSET) { | ||
const set = pipelinedRedisSet({ | ||
@@ -412,3 +415,3 @@ key, | ||
} else if (ttl === "Infinity") { | ||
if (pipelineRedisSET != null) { | ||
if (pipelineRedisSET) { | ||
const set = pipelinedRedisSet({ | ||
@@ -415,0 +418,0 @@ key, |
{ | ||
"name": "@soundxyz/fine-grained-cache", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"description": "Fine-grained cache helper using redis", | ||
@@ -46,2 +46,3 @@ "keywords": [ | ||
"concurrently": "^7.2.1", | ||
"date-fns": "^2.29.1", | ||
"esbuild": "^0.14.42", | ||
@@ -48,0 +49,0 @@ "execa": "^6.1.0", |
Sorry, the diff of this file is not supported yet
44858
1218
14