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
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { jsonCacheManager } from "@/lib/jsonCacheManager";
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const { products } = await request.json();
|
||||
|
||||
if (!products || !Array.isArray(products)) {
|
||||
return NextResponse.json(
|
||||
{ error: "Produtos inválidos" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// Salvar produtos no cache
|
||||
const result = await jsonCacheManager.saveProducts(products);
|
||||
|
||||
console.log(`[Cache Sync] ${result.saved} novos produtos salvos`);
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
saved: result.saved,
|
||||
failed: result.failed,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Erro ao sincronizar cache:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Erro ao sincronizar cache" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user