diff --git a/frontend/lib/caching/codeCache.ts b/frontend/lib/caching/codeCache.ts index 0897abcd..41127874 100644 --- a/frontend/lib/caching/codeCache.ts +++ b/frontend/lib/caching/codeCache.ts @@ -3,6 +3,8 @@ * 자주 사용되는 공통 코드들을 메모리에 캐싱하여 성능을 향상시킵니다. */ +import { commonCodeApi } from "@/lib/api/commonCode"; + interface CacheEntry { data: any; timestamp: number; @@ -86,6 +88,60 @@ class CodeCache { createCodeKey(category: string, companyCode?: string): string { return `code:${category}:${companyCode || "*"}`; } + + /** + * 여러 코드 카테고리를 배치로 미리 로딩 + */ + async preloadCodes(categories: string[]): Promise { + console.log(`🔄 코드 배치 로딩 시작: ${categories.join(", ")}`); + + const promises = categories.map(async (category) => { + try { + const response = await commonCodeApi.codes.getList(category, { isActive: true }); + if (response.success && response.data) { + const cacheKey = this.createCodeKey(category); + this.set(cacheKey, response.data, this.defaultTTL); + console.log(`✅ 코드 로딩 완료: ${category} (${response.data.length}개)`); + } + } catch (error) { + console.error(`❌ 코드 로딩 실패: ${category}`, error); + } + }); + + await Promise.all(promises); + console.log(`✅ 코드 배치 로딩 완료: ${categories.length}개 카테고리`); + } + + /** + * 코드를 동기적으로 조회 (캐시에서만) + */ + getCodeSync(category: string, companyCode?: string): any[] | null { + const cacheKey = this.createCodeKey(category, companyCode); + return this.get(cacheKey); + } + + /** + * 코드를 비동기적으로 조회 (캐시 미스 시 API 호출) + */ + async getCodeAsync(category: string, companyCode?: string): Promise { + const cached = this.getCodeSync(category, companyCode); + if (cached) { + return cached; + } + + try { + const response = await commonCodeApi.codes.getList(category, { isActive: true }); + if (response.success && response.data) { + const cacheKey = this.createCodeKey(category, companyCode); + this.set(cacheKey, response.data, this.defaultTTL); + return response.data; + } + } catch (error) { + console.error(`❌ 코드 조회 실패: ${category}`, error); + } + + return []; + } } // 싱글톤 인스턴스 생성 diff --git a/frontend/lib/registry/components/index.ts b/frontend/lib/registry/components/index.ts index cabedef9..80f690f3 100644 --- a/frontend/lib/registry/components/index.ts +++ b/frontend/lib/registry/components/index.ts @@ -35,7 +35,7 @@ import "./toggle-switch/ToggleSwitchRenderer"; import "./image-display/ImageDisplayRenderer"; import "./divider-line/DividerLineRenderer"; import "./accordion-basic/AccordionBasicRenderer"; -// import "./table-list/TableListRenderer"; // 임시 비활성화 +import "./table-list/TableListRenderer"; import "./card-display/CardDisplayRenderer"; /**