Merged in feat/sw-3596-cache (pull request #3106)
feat(SW-3598): Don't call redis api if cachetime=0 * feat(SW-3596): no cache if ttl=0 * Fixed on set as well * No cache if redemption * Revert no cache if redemption Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { type CacheTime, getCacheTimeInSeconds } from "../../Cache"
|
||||
import { cacheLogger } from "../../logger"
|
||||
import { cacheMap } from "./cacheMap"
|
||||
|
||||
export async function set<T>(
|
||||
@@ -6,8 +7,14 @@ export async function set<T>(
|
||||
data: T,
|
||||
ttl: CacheTime
|
||||
): Promise<void> {
|
||||
const cacheTimeInSeconds = getCacheTimeInSeconds(ttl)
|
||||
if (cacheTimeInSeconds <= 0) {
|
||||
cacheLogger.info(`'Trying to set ${key}' with ttl=0. Skipping cache!`)
|
||||
return
|
||||
}
|
||||
|
||||
cacheMap.set(key, {
|
||||
data: data,
|
||||
expiresAt: Date.now() + getCacheTimeInSeconds(ttl) * 1000,
|
||||
expiresAt: Date.now() + cacheTimeInSeconds * 1000,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user