From 9b491c53644b7d5100b9c3fa1e25348e572a7d17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20J=C3=A4derberg?= Date: Thu, 26 Jun 2025 06:23:03 +0000 Subject: [PATCH] Merged in fix/resolve-entry-clearing-cache (pull request #2445) fix: use shared cache key when revalidating urls * fix: use shared cache key when revalidating urls Approved-by: Linus Flood --- apps/scandic-web/app/api/web/revalidate/route.ts | 7 +++++-- apps/scandic-web/utils/entry.ts | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/scandic-web/app/api/web/revalidate/route.ts b/apps/scandic-web/app/api/web/revalidate/route.ts index e122c5340..e483f8c21 100644 --- a/apps/scandic-web/app/api/web/revalidate/route.ts +++ b/apps/scandic-web/app/api/web/revalidate/route.ts @@ -12,6 +12,7 @@ import { languageSwitcherAffix } from "@/server/routers/contentstack/languageSwi import { affix as metadataAffix } from "@/server/routers/contentstack/metadata/utils" import { affix as pageSettingsAffix } from "@/server/routers/contentstack/pageSettings/utils" +import { resolveEntryCacheKey } from "@/utils/entry" import { generateRefsResponseTag, generateRefTag, @@ -121,8 +122,10 @@ export async function POST(request: NextRequest) { await cacheClient.deleteKey(contentEntryTag, { fuzzy: true }) if (entry.url) { - console.info(`Revalidating url: ${entry.url}`) - await cacheClient.deleteKey(entry.url, { fuzzy: true }) + const resolveEntryTag = resolveEntryCacheKey(entryLocale, entry.url) + console.info(`Revalidating url: ${resolveEntryTag}`) + + await cacheClient.deleteKey(resolveEntryTag, { fuzzy: true }) } if (entry.breadcrumbs) { diff --git a/apps/scandic-web/utils/entry.ts b/apps/scandic-web/utils/entry.ts index 19991bdab..6f4e351a8 100644 --- a/apps/scandic-web/utils/entry.ts +++ b/apps/scandic-web/utils/entry.ts @@ -9,12 +9,16 @@ import { internalServerError } from "@/server/errors/next" import { validateEntryResolveSchema } from "@/types/requests/entry" +export function resolveEntryCacheKey(lang: Lang, url: string) { + return `${lang}:${url}:resolveentry` +} export async function resolve(url: string, lang = Lang.en) { const variables = { locale: lang, url: url || "/" } + const cacheKey = resolveEntryCacheKey(variables.locale, variables.url) + // The maximum amount of content types you can query is 6, therefor more // than that is being batched - const cacheKey = `${lang}:${url}:resolveentry` const response = await batchRequest([ { document: EntryByUrlBatch1,