refacto: tentative de refacto

This commit is contained in:
Julien Froidefond
2025-02-17 16:37:48 +01:00
parent 7ee99ac31a
commit ba725bb1a3
28 changed files with 195 additions and 170 deletions

View File

@@ -1,9 +1,3 @@
type CacheEntry = {
data: any;
timestamp: number;
ttl: number;
};
class ServerCacheService {
private static instance: ServerCacheService;
private cache: Map<string, { data: unknown; expiry: number }> = new Map();
@@ -94,14 +88,11 @@ class ServerCacheService {
type: keyof typeof ServerCacheService.DEFAULT_TTL = "DEFAULT"
): Promise<T> {
const now = Date.now();
console.log("👀 Getting or setting cache for key:", key);
const cached = this.cache.get(key);
if (cached && cached.expiry > now) {
console.log("✅ Cache hit for key:", key);
return cached.data as T;
}
console.log("❌ Cache not hit for key:", key);
try {
const data = await fetcher();