Files
web/apps/scandic-web/services/cms/fetchAndCacheEntry.ts
Linus Flood f183125bc6 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
2025-03-17 14:39:59 +00:00

28 lines
633 B
TypeScript

import { getCacheClient } from "@/services/dataCache"
import { resolve as resolveEntry } from "@/utils/entry"
import type { Lang } from "@/constants/languages"
export const fetchAndCacheEntry = async (path: string, lang: Lang) => {
path = path || "/"
const cacheKey = `${lang}:resolveentry:${path}`
const cache = await getCacheClient()
return cache.cacheOrGet(
cacheKey,
async (overrideTTL) => {
const { contentType, uid } = await resolveEntry(path, lang)
if (!contentType || !uid) {
overrideTTL?.("10m")
}
return {
contentType,
uid,
}
},
"1d"
)
}