Files
Evandro Fonseca Junior c173fec668 feat(api): implement product caching mechanism
- Add NODE_ENV=production to .env for environment configuration
- Enhance product API route with JSON cache manager for local storage and retrieval
- Introduce cache-only mode and detailed logging for better performance and offline support
- Update UI to display cache status and storage statistics
2025-10-09 04:30:46 -03:00

49 lines
1.3 KiB
TypeScript

import { NextResponse } from "next/server";
import { jsonCacheManager } from "@/lib/jsonCacheManager";
export async function GET() {
try {
console.log("[API] Iniciando busca de estatísticas do storage...");
// Verificar se o cache JSON está inicializado
const isInitialized = await jsonCacheManager.isInitialized();
if (!isInitialized) {
console.log("[API] Cache JSON não inicializado, retornando dados vazios");
return NextResponse.json({
success: true,
data: {
totalProducts: 0,
storageSizeMB: 0,
lastUpdated: 0,
averageProductSize: 0,
},
timestamp: Date.now(),
});
}
// Obter estatísticas do storage JSON
const stats = await jsonCacheManager.getStorageStats();
console.log("[API] Estatísticas obtidas:", stats);
return NextResponse.json({
success: true,
data: stats,
timestamp: Date.now(),
});
} catch (error) {
console.error("[API] Erro ao obter estatísticas do storage:", error);
// Retornar dados vazios em caso de erro para não quebrar o frontend
return NextResponse.json({
success: true,
data: {
totalProducts: 0,
storageSizeMB: 0,
lastUpdated: 0,
averageProductSize: 0,
},
timestamp: Date.now(),
});
}
}