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
28 lines
633 B
TypeScript
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"
|
|
)
|
|
}
|