refactor: improve cache handling and logging in CategoryList component to prioritize prerendered cache and enhance data fetching clarity
This commit is contained in:
@@ -174,20 +174,27 @@ class CategoryList extends Component {
|
||||
// Ensure cache exists
|
||||
windowObj.productCache = windowObj.productCache || {};
|
||||
|
||||
// Get cache key
|
||||
const cacheKey = `categoryTree_209_${currentLanguage}`;
|
||||
// The cache is PRERENDERED - always use it first!
|
||||
console.log('CategoryList: Checking prerendered cache', windowObj.productCache);
|
||||
|
||||
// Use either language-specific or default cache
|
||||
const cacheKey = `categoryTree_209_${currentLanguage}`;
|
||||
const defaultCacheKey = "categoryTree_209";
|
||||
|
||||
// Try language-specific cache first, then fall back to default
|
||||
const categoryTree =
|
||||
windowObj.productCache[cacheKey]?.categoryTree ||
|
||||
windowObj.productCache[defaultCacheKey]?.categoryTree;
|
||||
|
||||
// USE THE CACHE directly - if it has data, use it
|
||||
const categoryTree = windowObj.productCache[cacheKey]?.categoryTree;
|
||||
if (categoryTree) {
|
||||
console.log('CategoryList: Using cached category tree');
|
||||
console.log('CategoryList: Using prerendered cache');
|
||||
this.processCategoryTree(categoryTree);
|
||||
this.setState({ fetchedCategories: true });
|
||||
return;
|
||||
}
|
||||
|
||||
// No cache, so fetch
|
||||
console.log('CategoryList: Cache not found, fetching from socket');
|
||||
// Only fetch if no prerendered cache exists
|
||||
console.log('CategoryList: No prerendered cache, fetching from socket');
|
||||
windowObj.productCache[cacheKey] = { fetching: true, timestamp: Date.now() };
|
||||
this.setState({ fetchedCategories: true });
|
||||
window.socketManager.emit("categoryList", { categoryId: 209, language: currentLanguage, requestTranslation: true }, (response) => {
|
||||
|
||||
Reference in New Issue
Block a user