Fix cache folder issue - rename cache to caching to avoid gitignore

This commit is contained in:
hyeonsu 2025-09-18 19:15:13 +09:00
parent 35f8e37d1a
commit 7c21c2eba6
3 changed files with 107 additions and 2 deletions

View File

@ -0,0 +1,105 @@
/**
*
* .
*/
interface CacheEntry {
data: any;
timestamp: number;
expiry: number;
}
class CodeCache {
private cache = new Map<string, CacheEntry>();
private defaultTTL = 5 * 60 * 1000; // 5분
/**
*
*/
set(key: string, data: any, ttl?: number): void {
const expiry = ttl || this.defaultTTL;
const entry: CacheEntry = {
data,
timestamp: Date.now(),
expiry,
};
this.cache.set(key, entry);
}
/**
*
*/
get(key: string): any | null {
const entry = this.cache.get(key);
if (!entry) {
return null;
}
// TTL 체크
if (Date.now() - entry.timestamp > entry.expiry) {
this.cache.delete(key);
return null;
}
return entry.data;
}
/**
*
*/
delete(key: string): boolean {
return this.cache.delete(key);
}
/**
*
*/
clear(): void {
this.cache.clear();
}
/**
*
*/
cleanup(): void {
const now = Date.now();
for (const [key, entry] of this.cache.entries()) {
if (now - entry.timestamp > entry.expiry) {
this.cache.delete(key);
}
}
}
/**
*
*/
getStats(): { size: number; keys: string[] } {
return {
size: this.cache.size,
keys: Array.from(this.cache.keys()),
};
}
/**
*
*/
createCodeKey(category: string, companyCode?: string): string {
return `code:${category}:${companyCode || "*"}`;
}
}
// 싱글톤 인스턴스 생성
const codeCache = new CodeCache();
// 주기적으로 만료된 캐시 정리 (10분마다)
if (typeof window !== "undefined") {
setInterval(
() => {
codeCache.cleanup();
},
10 * 60 * 1000,
);
}
export default codeCache;
export { CodeCache, codeCache };

View File

@ -4,7 +4,7 @@
*/ */
import { useState, useEffect, useCallback, useMemo, useRef } from "react"; import { useState, useEffect, useCallback, useMemo, useRef } from "react";
import { codeCache } from "@/lib/cache/codeCache"; import { codeCache } from "@/lib/caching/codeCache";
interface ColumnMetaInfo { interface ColumnMetaInfo {
webType?: string; webType?: string;

View File

@ -4,7 +4,7 @@ import React, { useState, useEffect, useMemo } from "react";
import { TableListConfig, ColumnConfig } from "./types"; import { TableListConfig, ColumnConfig } from "./types";
import { tableTypeApi } from "@/lib/api/screen"; import { tableTypeApi } from "@/lib/api/screen";
import { entityJoinApi } from "@/lib/api/entityJoin"; import { entityJoinApi } from "@/lib/api/entityJoin";
import { codeCache } from "@/lib/cache/codeCache"; import { codeCache } from "@/lib/caching/codeCache";
import { useEntityJoinOptimization } from "@/lib/hooks/useEntityJoinOptimization"; import { useEntityJoinOptimization } from "@/lib/hooks/useEntityJoinOptimization";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input"; import { Input } from "@/components/ui/input";