feat: enhance cache clearing process with revalidation of important paths and improve logging in BaseApiService
This commit is contained in:
10
src/app/api/komga/cache/clear/route.ts
vendored
10
src/app/api/komga/cache/clear/route.ts
vendored
@@ -3,11 +3,19 @@ import type { ServerCacheService } from "@/lib/services/server-cache.service";
|
|||||||
import { getServerCacheService } from "@/lib/services/server-cache.service";
|
import { getServerCacheService } from "@/lib/services/server-cache.service";
|
||||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||||
import { getErrorMessage } from "@/utils/errors";
|
import { getErrorMessage } from "@/utils/errors";
|
||||||
|
import { revalidatePath } from "next/cache";
|
||||||
|
|
||||||
export async function POST() {
|
export async function POST() {
|
||||||
try {
|
try {
|
||||||
const cacheService: ServerCacheService = await getServerCacheService();
|
const cacheService: ServerCacheService = await getServerCacheService();
|
||||||
cacheService.clear();
|
await cacheService.clear();
|
||||||
|
|
||||||
|
// Revalider toutes les pages importantes après le vidage du cache
|
||||||
|
revalidatePath("/");
|
||||||
|
revalidatePath("/libraries");
|
||||||
|
revalidatePath("/series");
|
||||||
|
revalidatePath("/books");
|
||||||
|
|
||||||
return NextResponse.json({ message: "🧹 Cache vidé avec succès" });
|
return NextResponse.json({ message: "🧹 Cache vidé avec succès" });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Erreur lors de la suppression du cache:", error);
|
console.error("Erreur lors de la suppression du cache:", error);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { ERROR_CODES } from "../../constants/errorCodes";
|
|||||||
import { AppError } from "../../utils/errors";
|
import { AppError } from "../../utils/errors";
|
||||||
import type { KomgaConfig } from "@/types/komga";
|
import type { KomgaConfig } from "@/types/komga";
|
||||||
import type { ServerCacheService } from "./server-cache.service";
|
import type { ServerCacheService } from "./server-cache.service";
|
||||||
import { fetchWithCacheDetection } from "../utils/fetch-with-cache-detection";
|
import { DebugService } from "./debug.service";
|
||||||
// Types de cache disponibles
|
// Types de cache disponibles
|
||||||
export type CacheType = "DEFAULT" | "HOME" | "LIBRARIES" | "SERIES" | "BOOKS" | "IMAGES";
|
export type CacheType = "DEFAULT" | "HOME" | "LIBRARIES" | "SERIES" | "BOOKS" | "IMAGES";
|
||||||
|
|
||||||
@@ -97,8 +97,19 @@ export abstract class BaseApiService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const startTime = performance.now();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetchWithCacheDetection(url, { headers, ...options });
|
const response = await fetch(url, { headers, ...options });
|
||||||
|
const endTime = performance.now();
|
||||||
|
|
||||||
|
// Logger la requête côté serveur
|
||||||
|
await DebugService.logRequest({
|
||||||
|
url: url,
|
||||||
|
startTime,
|
||||||
|
endTime,
|
||||||
|
fromCache: false, // Côté serveur, on ne peut pas détecter le cache navigateur
|
||||||
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new AppError(ERROR_CODES.KOMGA.HTTP_ERROR, {
|
throw new AppError(ERROR_CODES.KOMGA.HTTP_ERROR, {
|
||||||
@@ -109,6 +120,16 @@ export abstract class BaseApiService {
|
|||||||
|
|
||||||
return options.isImage ? (response as T) : response.json();
|
return options.isImage ? (response as T) : response.json();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
const endTime = performance.now();
|
||||||
|
|
||||||
|
// Logger l'erreur côté serveur
|
||||||
|
await DebugService.logRequest({
|
||||||
|
url: url,
|
||||||
|
startTime,
|
||||||
|
endTime,
|
||||||
|
fromCache: false,
|
||||||
|
});
|
||||||
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user