Merged in feature/warmup (pull request #1887)
* unified warmup function Approved-by: Linus Flood
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import { type CacheTime, type DataCache } from "@/services/dataCache/Cache"
|
||||
|
||||
import {
|
||||
type CacheOrGetOptions,
|
||||
shouldGetFromCache,
|
||||
} from "../cacheOrGetOptions"
|
||||
import { cacheLogger } from "../logger"
|
||||
import { generateCacheKey } from "./generateCacheKey"
|
||||
import { get } from "./get"
|
||||
@@ -8,10 +12,15 @@ import { set } from "./set"
|
||||
export const cacheOrGet: DataCache["cacheOrGet"] = async <T>(
|
||||
key: string | string[],
|
||||
callback: (overrideTTL: (cacheTime: CacheTime) => void) => Promise<T>,
|
||||
ttl: CacheTime
|
||||
ttl: CacheTime,
|
||||
opts?: CacheOrGetOptions
|
||||
) => {
|
||||
const cacheKey = generateCacheKey(key)
|
||||
const cachedValue = await get<T>(cacheKey)
|
||||
|
||||
let cachedValue: Awaited<T> | undefined = undefined
|
||||
if (shouldGetFromCache(opts)) {
|
||||
cachedValue = await get<T>(cacheKey)
|
||||
}
|
||||
|
||||
let realTTL = ttl
|
||||
|
||||
|
||||
Reference in New Issue
Block a user