fix: 最新港剧偶发整栏消失 — 空结果不进60s缓存/客户端重试3次+localStorage持久缓存+失败重试入口 (fixed127)
Docker Build & Test / build (push) Canceled after 0s
Docker Build & Test / test (push) Canceled after 0s
Build & Push Docker image / build-and-push (linux/amd64) (push) Canceled after 0s
Build & Push Docker image / build-and-push (linux/arm/v7) (push) Canceled after 0s
Build & Push Docker image / build-and-push (linux/arm64) (push) Canceled after 0s
Build & Push Docker image / merge-images (push) Canceled after 0s

This commit is contained in:
3970260761 committed 2026-11-12 13:07:11 +08:00
1 parent 1e32753397
commit 6cbf7859f0
3 files changed
+91 -45

No files matched your search

+5 -2
View File
@@ -159,13 +159,16 @@ export async function GET(request: NextRequest) {
const cacheKey = searchParams.toString();
const now = Date.now();
const c = respCache.get(cacheKey);
if (c && now - c[0] < 60000) {
// 空结果只缓存 5s:上游偶发超时不能把空列表当 60s 正常数据缓存(最新港剧整栏消失的根因之一)
const cTTL = c && c[1] && Array.isArray(c[1].list) && c[1].list.length ? 60000 : 5000;
if (c && now - c[0] < cTTL) {
return NextResponse.json(c[1], { headers: { 'Access-Control-Allow-Origin': '*', 'Cache-Control': 'public, max-age=60', 'X-Cache': 'HIT' } });
}
const config = await getConfig();
const sourceConfigs: SrcCfg[] = (config.SourceConfig || []).filter((s: any) => !s.disabled);
const r = await aggregateAll(sourceConfigs, searchParams);
respCache.set(cacheKey, [now, r]);
// 只缓存有数据的结果;空结果短缓存(上面 5s TTL)且不长期驻留
if (r && Array.isArray(r.list) && r.list.length) respCache.set(cacheKey, [now, r]);
// 防止缓存无限增长:超过 200 条清空
if (respCache.size > 200) respCache.clear();
return NextResponse.json(r, { headers: { 'Access-Control-Allow-Origin': '*', 'Cache-Control': 'public, max-age=60' } });