emby列表增加内存缓存

This commit is contained in:
mtvpls
2026-01-03 12:13:04 +08:00
parent 97488c3bee
commit 2616b70365
4 changed files with 136 additions and 2 deletions
+11
View File
@@ -6,6 +6,7 @@ import { getAuthInfoFromCookie } from '@/lib/auth';
import { getConfig } from '@/lib/config';
import { db } from '@/lib/db';
import { EmbyClient } from '@/lib/emby.client';
import { clearEmbyCache } from '@/lib/emby-cache';
export const runtime = 'nodejs';
@@ -176,6 +177,16 @@ export async function POST(request: NextRequest) {
});
}
if (action === 'clearCache') {
// 清除缓存
const result = clearEmbyCache();
return NextResponse.json({
success: true,
message: `已清除 ${result.cleared} 条 Emby 缓存`,
cleared: result.cleared,
});
}
return NextResponse.json({ error: '不支持的操作' }, { status: 400 });
} catch (error) {
console.error('Emby 配置保存失败:', error);
+14 -2
View File
@@ -4,6 +4,7 @@ import { NextRequest, NextResponse } from 'next/server';
import { getConfig } from '@/lib/config';
import { EmbyClient } from '@/lib/emby.client';
import { getCachedEmbyList, setCachedEmbyList } from '@/lib/emby-cache';
export const runtime = 'nodejs';
@@ -13,6 +14,12 @@ export async function GET(request: NextRequest) {
const pageSize = parseInt(searchParams.get('pageSize') || '20');
try {
// 检查缓存
const cached = getCachedEmbyList(page, pageSize);
if (cached) {
return NextResponse.json(cached);
}
const config = await getConfig();
const embyConfig = config.EmbyConfig;
@@ -78,13 +85,18 @@ export async function GET(request: NextRequest) {
const totalPages = Math.ceil(result.TotalRecordCount / pageSize);
return NextResponse.json({
const response = {
success: true,
list,
totalPages,
currentPage: page,
total: result.TotalRecordCount,
});
};
// 缓存结果
setCachedEmbyList(page, pageSize, response);
return NextResponse.json(response);
} catch (error) {
console.error('获取 Emby 列表失败:', error);
return NextResponse.json({