Commit d810333f by 杨树贤

分类加上缓存

parent 1d86301f
Showing with 14 additions and 1 deletions
......@@ -9,6 +9,10 @@ class ClassService
//获取首页需要的所有分类,没有英文名称的不要
public static function getClassificationForHome()
{
$cache = Redis::get('semour_classification_cache');
if ($cache) {
return json_decode($cache, true);
}
//先获取所有分类
$classData = \Http::get(config('website.footstone_url') . '/open/getClassification')->json();
$secondClassList = [];
......@@ -56,13 +60,20 @@ class ClassService
}
}
}
return array_values($topFields);
$data = array_values($topFields);
Redis::set('semour_classification_cache', json_encode($data));
Redis::expire('semour_classification_cache', 600);
return $data;
}
return [];
}
public static function getClassificationById($classId, $includeChildren = false)
{
$cache = Redis::get('semour_classification_cache_' . $classId);
if ($cache) {
return json_decode($cache, true);
}
$classData = \Http::get(config('website.footstone_url') . '/open/getClassification')->json();
if (isset($classData['code']) && $classData['code'] == 0) {
$classificationCache = $classData['data'];
......@@ -87,6 +98,8 @@ class ClassService
}
}
$classification['sku_number'] = $totalSkuNumber;
Redis::set('semour_classification_cache_' . $classId, json_encode($classification));
Redis::expire('semour_classification_cache_' . $classId, 600);
return $classification;
}
return [];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment