|
1 | 1 | // deno-lint-ignore-file no-explicit-any |
2 | 2 | import { HTTPException } from "@hono/hono/http-exception"; |
3 | 3 | import { DECO_MATCHER_HEADER_QS } from "../blocks/matcher.ts"; |
4 | | -import { PAGE_DIRTY_KEY } from "../blocks/utils.tsx"; |
| 4 | +import { PAGE_CACHE_ALLOWED_KEY } from "../blocks/utils.tsx"; |
5 | 5 | import { Context, context } from "../deco.ts"; |
6 | 6 | import { |
7 | 7 | type Exception, |
@@ -106,7 +106,6 @@ async (ctx, next) => { |
106 | 106 |
|
107 | 107 | const DEBUG_COOKIE = "deco_debug"; |
108 | 108 | const DEBUG_ENABLED = "enabled"; |
109 | | -const PAGE_CACHE_ENABLED = Deno.env.get("DECO_PAGE_CACHE_ENABLED") === "true"; |
110 | 109 | const PAGE_CACHE_CONTROL = Deno.env.get("DECO_PAGE_CACHE_CONTROL") ?? |
111 | 110 | "public, max-age=90, s-maxage=90, stale-while-revalidate=3600, stale-if-error=86400"; |
112 | 111 |
|
@@ -430,12 +429,12 @@ export const middlewareFor = <TAppManifest extends AppManifest = AppManifest>( |
430 | 429 | const hasSetCookie = getSetCookies(newHeaders).length > 0; |
431 | 430 | const contentType = newHeaders.get("Content-Type") ?? ""; |
432 | 431 | const isHtmlResponse = contentType.includes("text/html"); |
433 | | - const isPageDirty = ctx.var.bag?.has(PAGE_DIRTY_KEY); |
| 432 | + const isPageCacheAllowed = ctx.var.bag?.has(PAGE_CACHE_ALLOWED_KEY); |
434 | 433 |
|
435 | 434 | if (hasSetCookie) { |
436 | 435 | // Set-cookie present: never cache (same behavior as main) |
437 | 436 | newHeaders.set("Cache-Control", "no-store, no-cache, must-revalidate"); |
438 | | - } else if (isHtmlResponse && PAGE_CACHE_ENABLED && !isPageDirty) { |
| 437 | + } else if (isHtmlResponse && isPageCacheAllowed) { |
439 | 438 | const flags = ctx.var?.flags ?? []; |
440 | 439 | const allFlagsCacheable = flags.length > 0 |
441 | 440 | ? flags.every((flag) => flag.cacheable === true) |
|
0 commit comments