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:
Evandro Fonseca Junior committed 2025-10-09 04:30:46 -03:00
1 parent bddf19e5c8
commit c173fec668
19 files changed
+9240 -175

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
"use client";
import { useState, useEffect } from "react";
export function useCacheOnlyMode() {
const [cacheOnly, setCacheOnly] = useState(false);
const isProd = process.env.NODE_ENV === "production";
useEffect(() => {
if (isProd) {
const saved = localStorage.getItem("cache_only_mode");
setCacheOnly(saved === "true");
}
}, [isProd]);
useEffect(() => {
const handleStorageChange = () => {
const saved = localStorage.getItem("cache_only_mode");
setCacheOnly(saved === "true");
};
window.addEventListener("storage", handleStorageChange);
return () => window.removeEventListener("storage", handleStorageChange);
}, []);
return {
cacheOnly: isProd ? cacheOnly : false,
isProd,
};
}