Skip to content

Commit 7e36176

Browse files
fix(cache): increase stale-while-revalidate TTL to 1 hour (#1136)
* fix(cache): increase stale-while-revalidate TTL to 1 hour - STALE_TTL_PERIOD default: 30s → 3600s (1h) Keeps loader cache entries in LRU as stale fallback during origin slowdowns. Previously items were evicted after 90s total (60s fresh + 30s stale), leaving cache misses exposed to full origin latency. - DECO_PAGE_CACHE_CONTROL stale-while-revalidate: 30s → 3600s (1h) CDN can serve stale HTML for up to 1h while revalidating in background, reducing origin pressure during high latency spikes. Both values remain overridable via env vars. * fix(cache): add stale-if-error=86400 to page cache control Aligns middleware PAGE_CACHE_CONTROL with the existing pattern in routes/render.tsx. Ensures CDN serves stale HTML on origin errors (5xx, timeout) for up to 24h, regardless of CDN implementation. * fix(cache): prevent NaN ttl when expires header is missing Date.parse('') returns NaN, causing ttl = NaN + STALE_TTL_PERIOD = NaN. lru-cache disables TTL entirely when NaN is passed, making items persist indefinitely. Fall back to STALE_TTL_PERIOD when expires is absent. * Update cache control settings in middleware * Change default STALE_TTL_PERIOD from 1 hour to 30 seconds * Update runtime/middleware.ts Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> * Update middleware.ts * Update lrucache.ts --------- Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
1 parent c3004c3 commit 7e36176

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

runtime/middleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ const DEBUG_COOKIE = "deco_debug";
108108
const DEBUG_ENABLED = "enabled";
109109
const PAGE_CACHE_ENABLED = Deno.env.get("DECO_PAGE_CACHE_ENABLED") === "true";
110110
const PAGE_CACHE_CONTROL = Deno.env.get("DECO_PAGE_CACHE_CONTROL") ??
111-
"public, max-age=90, s-maxage=90, stale-while-revalidate=30";
111+
"public, max-age=90, s-maxage=90, stale-while-revalidate=3600, stale-if-error=86400";
112112

113113
export const DEBUG_QS = "__d";
114114
const addHours = (date: Date, h: number) => {

0 commit comments

Comments
 (0)