fix: cidCache 大小限制为500条,防止内存泄漏

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
saopig1andClaude Opus 4.6 committed 2026-03-30 20:20:42 +08:00
1 parent 5e4d318a2a
commit fbf8cc82de
1 file changed
+6
+6
View File
@@ -161,6 +161,12 @@ export class BiliBiliProvider implements MusicProvider {
const cached = this.cidCache.get(bvid); const cached = this.cidCache.get(bvid);
if (cached) return cached; if (cached) return cached;
// Limit cache size to prevent unbounded growth
if (this.cidCache.size > 500) {
const firstKey = this.cidCache.keys().next().value;
if (firstKey) this.cidCache.delete(firstKey);
}
const detail = await this.getSongDetail(bvid); const detail = await this.getSongDetail(bvid);
if (!detail) return null; if (!detail) return null;
return this.cidCache.get(bvid) ?? null; return this.cidCache.get(bvid) ?? null;