Merged in fix/cache-fixes (pull request #1555)

fix/cache: reduce cachetime when null response from CS. Fix fuzzy delete

* fix/cache: reduce cachetime when null response from CS. Fix fuzzy delete


Approved-by: Anton Gunnarsson
This commit is contained in:
Linus Flood
2025-03-17 14:39:59 +00:00
parent c5ad3cba34
commit f183125bc6
6 changed files with 33 additions and 11 deletions

View File

@@ -6,13 +6,18 @@ import { set } from "./set"
export const cacheOrGet: DataCache["cacheOrGet"] = async <T>(
key: string | string[],
callback: () => Promise<T>,
callback: (overrideTTL?: (cacheTime: CacheTime) => void) => Promise<T>,
ttl: CacheTime
): Promise<T> => {
if (Array.isArray(key)) {
key = key.join("-")
}
let realTTL = ttl
const overrideTTL = function (cacheTime: CacheTime) {
realTTL = cacheTime
}
const cached = await get(key)
if (cached) {
@@ -22,8 +27,8 @@ export const cacheOrGet: DataCache["cacheOrGet"] = async <T>(
cacheLogger.debug(`Miss for key '${key}'`)
try {
const data = await callback()
await set(key, data, ttl)
const data = await callback(overrideTTL)
await set(key, data, realTTL)
return data
} catch (e) {