Add missing getCacheInfo method to codeCache

This commit is contained in:
hyeonsu 2025-09-18 20:14:26 +09:00
parent 3fbbfb53c1
commit 30d01fc3bd
1 changed files with 29 additions and 0 deletions

View File

@ -142,6 +142,35 @@ class CodeCache {
return [];
}
/**
* ( )
*/
getCacheInfo(): {
size: number;
keys: string[];
totalMemoryUsage: number;
hitRate?: number;
} {
const stats = this.getStats();
// 메모리 사용량 추정 (대략적)
let totalMemoryUsage = 0;
for (const [key, entry] of this.cache.entries()) {
// 키 크기 + 데이터 크기 추정
totalMemoryUsage += key.length * 2; // 문자열은 UTF-16이므로 2바이트
if (Array.isArray(entry.data)) {
totalMemoryUsage += entry.data.length * 100; // 각 항목당 대략 100바이트로 추정
} else {
totalMemoryUsage += JSON.stringify(entry.data).length * 2;
}
}
return {
...stats,
totalMemoryUsage,
};
}
}
// 싱글톤 인스턴스 생성