Merged in fix/SW-2945-cache-timings-for-resolve-entry (pull request #2264)

Fix/SW-2945 cache timings for resolve entry

* fix: cache resolveentry() harder and revalidate on publish instead

* logging: use debug logging for requests and add logging when tll is invalid


Approved-by: Linus Flood
This commit is contained in:
Joakim Jäderberg
2025-06-02 08:35:55 +00:00
parent 651a388fa3
commit ef3b29b9f1
4 changed files with 14 additions and 9 deletions

View File

@@ -16,7 +16,7 @@ export const cacheRoutes = new Elysia({ prefix: "/cache" })
"/",
async ({ query: { key }, status }) => {
key = validateKey(key);
cacheRouteLogger.info(`GET /cache ${key}`);
cacheRouteLogger.debug(`GET /cache ${key}`);
const value = await redis.get(key);
if (!value) {
@@ -48,9 +48,12 @@ export const cacheRoutes = new Elysia({ prefix: "/cache" })
"/",
async ({ query: { key }, body, status, set }) => {
key = validateKey(key);
cacheRouteLogger.info(`PUT /cache ${key}`);
cacheRouteLogger.debug(`PUT /cache ${key}`);
if (!body.ttl || body.ttl < 0) {
cacheRouteLogger.warn(
`PUT /cache ${key} with ttl=${body.ttl}, will not cache the data`
);
return status("Bad Request", "ttl is required");
}
@@ -69,7 +72,7 @@ export const cacheRoutes = new Elysia({ prefix: "/cache" })
"/",
async ({ query: { key, fuzzy } }) => {
key = validateKey(key);
cacheRouteLogger.info(
cacheRouteLogger.debug(
`DELETE /cache ${key} ${fuzzy ? "fuzzy" : ""}`
);
const deletedKeys: number = fuzzy

View File

@@ -119,6 +119,11 @@ export async function POST(request: NextRequest) {
revalidateTag(contentEntryTag)
await cacheClient.deleteKey(contentEntryTag, { fuzzy: true })
if (entry.url) {
console.info(`Revalidating url: ${entry.url}`)
await cacheClient.deleteKey(entry.url, { fuzzy: true })
}
if (entry.breadcrumbs) {
const breadcrumbsRefsTag = generateRefsResponseTag(
entryLocale,

View File

@@ -12,6 +12,7 @@ services:
- PRIMARY_API_KEY=
- SECONDARY_API_KEY=
- NODE_ENV=development
- SENTRY_ENABLED=false
- SENTRY_DSN=fake-dsn
- SENTRY_ENVIRONMENT=development
redis:

View File

@@ -10,18 +10,14 @@ export const fetchAndCacheEntry = async (path: string, lang: Lang) => {
return cache.cacheOrGet(
cacheKey,
async (overrideTTL) => {
async () => {
const { contentType, uid } = await resolveEntry(path, lang)
if (!contentType || !uid) {
overrideTTL?.("10m")
}
return {
contentType,
uid,
}
},
"1d"
"max"
)
}