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,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,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user