fix(worker): bound docs HTML cache staleness

This commit is contained in:
Vincent Koc 2026-05-07 13:51:39 -07:00
parent d61516c7e1
commit 46b7ac7d79
No known key found for this signature in database

View File

@ -137,6 +137,9 @@ function r2RequestHeaders(request: Request): Headers {
function cacheRequest(request: Request, pathname: string): Request {
const url = new URL(request.url);
url.pathname = pathname;
if (isHtmlPath(pathname)) {
url.searchParams.set("__openclaw_docs_cache_minute", String(Math.floor(Date.now() / 60_000)));
}
return new Request(url.toString(), {
headers: request.headers,
method: "GET",
@ -151,7 +154,7 @@ function applyCacheHeaders(headers: Headers, pathname: string): void {
}
function browserCacheControlFor(pathname: string): string {
if (pathname.endsWith(".html") || !/\.[^/]+$/.test(pathname)) {
if (isHtmlPath(pathname)) {
return "public, max-age=60, stale-while-revalidate=60";
}
if (pathname.endsWith(".md") || pathname.endsWith(".txt") || pathname.endsWith(".json") || pathname.endsWith(".jsonl")) {
@ -161,8 +164,8 @@ function browserCacheControlFor(pathname: string): string {
}
function edgeCacheControlFor(pathname: string): string {
if (pathname.endsWith(".html") || !/\.[^/]+$/.test(pathname)) {
return "public, s-maxage=86400, stale-while-revalidate=604800";
if (isHtmlPath(pathname)) {
return "public, s-maxage=60, stale-while-revalidate=60";
}
if (pathname.endsWith(".md") || pathname.endsWith(".txt") || pathname.endsWith(".json") || pathname.endsWith(".jsonl")) {
return "public, s-maxage=3600, stale-while-revalidate=86400";
@ -170,6 +173,10 @@ function edgeCacheControlFor(pathname: string): string {
return "public, max-age=31536000, immutable";
}
function isHtmlPath(pathname: string): boolean {
return pathname.endsWith(".html") || !/\.[^/]+$/.test(pathname);
}
function appendVary(current: string | null, value: string): string {
const parts = new Set((current ?? "").split(",").map((part) => part.trim()).filter(Boolean));
parts.add(value);