From 75fcc094981865db88e15474f97c5c6d221e0ec6 Mon Sep 17 00:00:00 2001 From: mtvpls Date: Fri, 19 Dec 2025 00:00:21 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9F=AD=E5=89=A7=E6=8E=A8=E8=8D=90=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/api/duanju/recommends/route.ts | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/app/api/duanju/recommends/route.ts b/src/app/api/duanju/recommends/route.ts index 7b8fdf3..874fe8d 100644 --- a/src/app/api/duanju/recommends/route.ts +++ b/src/app/api/duanju/recommends/route.ts @@ -9,6 +9,12 @@ import { cleanHtmlTags } from '@/lib/utils'; export const runtime = 'nodejs'; +// 服务端内存缓存 +let cachedRecommends: { + timestamp: number; + data: SearchResult[]; +} | null = null; + interface ApiSearchItem { vod_id: string; vod_name: string; @@ -34,6 +40,27 @@ interface CmsClassResponse { */ export async function GET() { try { + // 检查内存缓存 + const now = Date.now(); + const CACHE_DURATION = 60 * 60 * 1000; // 1小时 + + if (cachedRecommends && now - cachedRecommends.timestamp < CACHE_DURATION) { + console.log('使用缓存的短剧推荐数据'); + const cacheTime = await getCacheTime(); + return NextResponse.json( + { + code: 200, + message: '获取成功', + data: cachedRecommends.data, + }, + { + headers: { + 'Cache-Control': `public, max-age=${cacheTime}, s-maxage=${cacheTime}`, + }, + } + ); + } + // 获取短剧视频源列表 const sources = await getDuanjuSources(); @@ -167,6 +194,12 @@ export async function GET() { console.log(`返回 ${filteredVideos.length} 个短剧视频`); + // 保存到内存缓存 + cachedRecommends = { + timestamp: Date.now(), + data: filteredVideos, + }; + const cacheTime = await getCacheTime(); return NextResponse.json( {