Authored by hf

add channel and guang page cache

... ... @@ -39,18 +39,20 @@ class DetailData
// 客户端类型
$clientType = $isApp ? 'iphone' : 'h5';
$key = CacheConfig::KEY_ACTION_GUANG_DETAIL_DATA . strval($id);
$key = CacheConfig::KEY_ACTION_GUANG_DETAIL_DATA . strval($id) . $clientType;
if (USE_CACHE) {
// 先尝试获取二级缓存(slave), 有数据则直接返回.
$cached = Cache::get($key, 'master');
if (!empty($cached)) {
return $cached;
}
}
return $result;
// 获取资讯
$article = Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_PACKAGE_ARTICLE, 'getArticle', array($id, $clientType), false, 1000);
if (!isset($article['author_id'])) {
if (USE_CACHE) {
// 先尝试获取二级缓存(slave), 有数据则直接返回.
$result = Cache::get($key, 'slave');
if (!empty($result)) {
return $result;
}
}
return $result;
}
$result['getArticle'] = $article;
... ... @@ -80,8 +82,15 @@ class DetailData
// 调用发起请求
Yohobuy::yarConcurrentLoop();
if (USE_CACHE && !empty($result['getArticle'])) {
Cache::set($key, $result);
if (USE_CACHE) {
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
if (empty($result)) {
$result = Cache::get($key, 'slave');
}
// 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
elseif (!empty($result['getArticle']) && !empty($result['getArticleContent'])) {
Cache::set($key, $result);
}
}
return $result;
... ...
... ... @@ -66,7 +66,7 @@ class ListData
}
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::SERVICE_URL . self::URI_ARTICLELIST, $param);
return Yohobuy::get(Yohobuy::SERVICE_URL . self::URI_ARTICLELIST, $param, 1800); // 缓存30分钟
}
/**
... ...
... ... @@ -20,6 +20,7 @@ use LibModels\Wap\Product\SearchData;
*/
class PlusstarData
{
const URI_BRANDLIST = 'guang/api/v1/plustar/getlist';
const URI_BRANDINFO_PLUSSTAR = 'guang/service/v1/plustar/';
const URI_BRANDINFO_FAVORITE = 'shops/service/v1/favorite/';
... ... @@ -126,30 +127,34 @@ class PlusstarData
$result['getUidProductFav'] = array();
$result['getArticleByBrand'] = array();
$key = CacheConfig::KEY_ACTION_GUANG_PLUSTAR_DATA . strval($id);
// 客户端类型
$clientType = $isApp ? 'iphone' : 'h5';
$key = CacheConfig::KEY_ACTION_GUANG_PLUSTAR_DATA . strval($id) . $clientType;
if (USE_CACHE) {
// 先尝试获取二级缓存(slave), 有数据则直接返回.
$cached = Cache::get($key, 'master');
if (!empty($cached)) {
return $cached;
}
}
return $result;
// 品牌详情信息
$brandInfo = Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_BRANDINFO_PLUSSTAR, 'getBrandInfo', array(array('id' => $id)), 3600); // 缓存1小时
if (!isset($brandInfo['data']['brand_id'])) {
if (USE_CACHE) {
// 先尝试获取二级缓存(slave), 有数据则直接返回.
$result = Cache::get($key, 'slave');
if (!empty($result)) {
return $result;
}
}
return $result;
} else {
$result['getBrandInfo'] = $brandInfo;
}
// 是否收藏店铺
$isUidOk = $uid && is_numeric($uid);
if ($isUidOk) {
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_BRANDINFO_FAVORITE, 'getUidBrandFav', array($uid, $brandInfo['data']['brand_id']), function($retval) use(&$result) {
$result['getUidBrandFav'] = (isset($retval['message']) && $retval['message'] == 'favorite') ? true : false;
});
}
// // 是否收藏店铺
// $isUidOk = $uid && is_numeric($uid);
// if ($isUidOk) {
// Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_BRANDINFO_FAVORITE, 'getUidBrandFav', array($uid, $brandInfo['data']['brand_id']), function($retval) use(&$result) {
// $result['getUidBrandFav'] = (isset($retval['message']) && $retval['message'] == 'favorite') ? true : false;
// });
// }
// 相关资讯列表 (3篇)
$result['getArticleByBrand'] = array();
... ... @@ -179,7 +184,7 @@ class PlusstarData
$condition['limit'] = 6;
$condition['order'] = 's_t_desc';
$newProduct = SearchData::searchElasticByCondition($condition, 1800); // 有缓存30分钟
if (empty($newProduct['data']['product_list'])) {
break;
}
... ... @@ -202,11 +207,11 @@ class PlusstarData
// 用户是否收藏该商品
$skn = $value['product_skn'];
$result['getUidProductFav'][$skn] = false;
if ($isUidOk) {
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_BRANDINFO_FAVORITE, 'getUidProductFav', array($uid, $value['product_skn']), function($retval) use(&$result, &$skn) {
$result['getUidProductFav'][$skn] = empty($retval['data']) ? false : $retval['data'];
});
}
// if ($isUidOk) {
// Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_BRANDINFO_FAVORITE, 'getUidProductFav', array($uid, $value['product_skn']), function($retval) use(&$result, &$skn) {
// $result['getUidProductFav'][$skn] = empty($retval['data']) ? false : $retval['data'];
// });
// }
$i ++;
}
... ... @@ -215,11 +220,16 @@ class PlusstarData
// 调用发起请求
Yohobuy::yarConcurrentLoop();
if (USE_CACHE && !empty($result['getBrandInfo'])) {
if (USE_CACHE) {
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
if (empty($result)) {
$result = Cache::get($key, 'slave');
}
// 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
Cache::set($key, $result);
elseif (!empty($result['getBrandInfo'])) {
Cache::set($key, $result);
}
}
return $result;
}
... ...
... ... @@ -3,6 +3,8 @@
use Action\AbstractAction;
use LibModels\Wap\Guang\ListData;
use Plugin\Helpers;
use Plugin\Cache;
use Configs\CacheConfig;
/**
* 逛首页、列表页、编辑页
... ... @@ -264,5 +266,31 @@ class IndexController extends AbstractAction
echo ' ';
}
}
/**
* @todo 清缓存
*/
public function clearAction()
{
$type = $this->get('type');
switch (strval($type)) {
case 'boys':
Cache::delete(CacheConfig::KEY_ACTION_BOYS_INDEX);
break;
case 'girls':
Cache::delete(CacheConfig::KEY_ACTION_GIRLS_INDEX);
break;
case 'kids':
Cache::delete(CacheConfig::KEY_ACTION_KIDS_INDEX);
break;
case 'lifestyle':
Cache::delete(CacheConfig::KEY_ACTION_LIFESTYLE_INDEX);
break;
case 'bgimg':
Cache::delete(CacheConfig::KEY_ACTION_INDEX_INDEX);
break;
}
}
}
... ...