Merged in feature/warmup (pull request #1887)

* unified warmup function

Approved-by: Linus Flood
This commit is contained in:
Joakim Jäderberg
2025-04-29 06:18:14 +00:00
parent bbbd665a32
commit c1505ce50e
33 changed files with 886 additions and 185 deletions

View File

@@ -1,4 +1,4 @@
import { unstable_cache } from "next/cache"
import { revalidateTag, unstable_cache } from "next/cache"
import {
type CacheTime,
@@ -6,18 +6,26 @@ import {
getCacheTimeInSeconds,
} from "@/services/dataCache/Cache"
import {
type CacheOrGetOptions,
shouldGetFromCache,
} from "../../cacheOrGetOptions"
import { cacheLogger } from "../../logger"
export const cacheOrGet: DataCache["cacheOrGet"] = async <T>(
key: string | string[],
callback: () => Promise<T>,
ttl: CacheTime
ttl: CacheTime,
opts?: CacheOrGetOptions
): Promise<T> => {
if (!Array.isArray(key)) {
key = [key]
}
const perf = performance.now()
if (!shouldGetFromCache(opts)) {
revalidateTag(key[0])
}
const res = await unstable_cache(callback, key, {
revalidate: getCacheTimeInSeconds(ttl),