From a3f8b011f3211af800d77346c8d779b55d5b4ee3 Mon Sep 17 00:00:00 2001 From: Julien Froidefond Date: Fri, 14 Feb 2025 13:29:41 +0100 Subject: [PATCH] refacto: cleaning old files --- src/app/api/komga/home/route.ts | 17 ---- src/lib/services/client-cache.service.ts | 121 ----------------------- 2 files changed, 138 deletions(-) delete mode 100644 src/app/api/komga/home/route.ts delete mode 100644 src/lib/services/client-cache.service.ts diff --git a/src/app/api/komga/home/route.ts b/src/app/api/komga/home/route.ts deleted file mode 100644 index 55002db..0000000 --- a/src/app/api/komga/home/route.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { NextResponse } from "next/server"; -import { HomeService } from "@/lib/services/home.service"; - -export const dynamic = "force-dynamic"; - -export async function GET() { - try { - const data = await HomeService.getHomeData(); - return NextResponse.json(data); - } catch (error) { - console.error("API Home - Erreur:", error); - return NextResponse.json( - { error: "Erreur lors de la récupération des données" }, - { status: 500 } - ); - } -} diff --git a/src/lib/services/client-cache.service.ts b/src/lib/services/client-cache.service.ts deleted file mode 100644 index 138ed26..0000000 --- a/src/lib/services/client-cache.service.ts +++ /dev/null @@ -1,121 +0,0 @@ -import { TTLConfig } from "@/types/cache"; - -class ClientCacheService { - private static instance: ClientCacheService; - private cache: Map = new Map(); - - private static readonly DEFAULT_TTL = { - DEFAULT: 5 * 60, - HOME: 5 * 60, - LIBRARIES: 24 * 60 * 60, - SERIES: 5 * 60, - BOOKS: 5 * 60, - IMAGES: 24 * 60 * 60, - }; - - private constructor() { - // Private constructor to prevent external instantiation - } - - public static getInstance(): ClientCacheService { - if (!ClientCacheService.instance) { - ClientCacheService.instance = new ClientCacheService(); - } - return ClientCacheService.instance; - } - - /** - * Retourne le TTL pour un type de données spécifique - */ - public getTTL(type: keyof typeof ClientCacheService.DEFAULT_TTL): number { - try { - const ttlConfig = localStorage.getItem("ttlConfig"); - if (ttlConfig) { - const config = JSON.parse(ttlConfig) as TTLConfig; - const key = `${type.toLowerCase()}TTL` as keyof TTLConfig; - if (config[key]) { - // Convertir les minutes en secondes - return config[key] * 60; - } - } - } catch (error) { - console.error("Erreur lors de la lecture de la configuration TTL:", error); - } - - return ClientCacheService.DEFAULT_TTL[type]; - } - - /** - * Met en cache des données avec une durée de vie - */ - set(key: string, data: any, type: keyof typeof ClientCacheService.DEFAULT_TTL = "DEFAULT"): void { - this.cache.set(key, { - data, - expiry: Date.now() + this.getTTL(type) * 1000, - }); - } - - /** - * Récupère des données du cache si elles sont valides - */ - get(key: string): any | null { - const cached = this.cache.get(key); - if (!cached) return null; - - const now = Date.now(); - if (cached.expiry > now) { - return cached.data; - } - - this.cache.delete(key); - return null; - } - - /** - * Supprime une entrée du cache - */ - delete(key: string): void { - this.cache.delete(key); - } - - /** - * Vide le cache - */ - clear(): void { - this.cache.clear(); - } - - /** - * Récupère des données du cache ou exécute la fonction si nécessaire - */ - async getOrSet( - key: string, - fetcher: () => Promise, - type: keyof typeof ClientCacheService.DEFAULT_TTL = "DEFAULT" - ): Promise { - const now = Date.now(); - const cached = this.cache.get(key); - - if (cached && cached.expiry > now) { - console.log("Cache hit for key:", key); - return cached.data as T; - } - - try { - const data = await fetcher(); - this.cache.set(key, { - data, - expiry: now + this.getTTL(type) * 1000, - }); - return data; - } catch (error) { - throw error; - } - } - - invalidate(key: string): void { - this.cache.delete(key); - } -} - -export const clientCacheService = ClientCacheService.getInstance();