diff --git a/frontend/lib/caching/codeCache.ts b/frontend/lib/caching/codeCache.ts index 41127874..d7d2d65b 100644 --- a/frontend/lib/caching/codeCache.ts +++ b/frontend/lib/caching/codeCache.ts @@ -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, + }; + } } // 싱글톤 인스턴스 생성