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
This commit is contained in:
1 parent
bddf19e5c8
commit
c173fec668
19 files changed
+9240
-175
No files matched your search
@@ -0,0 +1,48 @@
|
||||
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(),
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user