fix(server): reduced cache layer logging noise (#4530)
This commit is contained in:
committed by
GitHub
parent
374c15e56f
commit
d579239dab
@@ -51,6 +51,10 @@ type WrapWithCacheBaseParams<Args extends Array<any>> = {
|
||||
* Default: true
|
||||
*/
|
||||
cachePromises?: boolean
|
||||
/**
|
||||
* Logger log level. Defaults to 'debug'
|
||||
*/
|
||||
logLevel?: 'info' | 'debug'
|
||||
}>
|
||||
}
|
||||
|
||||
@@ -67,6 +71,7 @@ export const wrapWithCache = <Args extends Array<any>, Results>(
|
||||
const cachePromises = params.options?.cachePromises ?? true
|
||||
const { argsKey = (...args: Args) => JSON.stringify(args) } = options || {}
|
||||
const key = (...args: Args) => `wrapWithCache:${name}:${argsKey(...args)}`
|
||||
const logLevel = options?.logLevel || 'debug'
|
||||
|
||||
const buildResolver =
|
||||
(
|
||||
@@ -84,14 +89,14 @@ export const wrapWithCache = <Args extends Array<any>, Results>(
|
||||
})
|
||||
|
||||
if (skipCache) {
|
||||
logger.info("Cache '{cacheName}' skipped for specific args")
|
||||
logger[logLevel]("Cache '{cacheName}' skipped for specific args")
|
||||
} else {
|
||||
const cached = await cacheProvider.get(cacheKey)
|
||||
if (cached !== undefined) {
|
||||
logger.info("Cache '{cacheName}' hit for specific args")
|
||||
logger[logLevel]("Cache '{cacheName}' hit for specific args")
|
||||
return cached as Results
|
||||
} else {
|
||||
logger.info("Cache '{cacheName}' miss for specific args")
|
||||
logger[logLevel]("Cache '{cacheName}' miss for specific args")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +144,7 @@ export const wrapWithCache = <Args extends Array<any>, Results>(
|
||||
const logger = (getRequestLogger() || cacheLogger).child({ cacheName: name })
|
||||
|
||||
await cacheProvider.delete(cacheKey)
|
||||
logger.info("Cache '{cacheName}' cleared for specific args")
|
||||
logger[logLevel]("Cache '{cacheName}' cleared for specific args")
|
||||
}
|
||||
|
||||
ret.fresh = freshResolver
|
||||
|
||||
Reference in New Issue
Block a user