Authored by htoooth

dispose cache

@@ -6,12 +6,10 @@ @@ -6,12 +6,10 @@
6 6
7 const api = global.yoho.API; 7 const api = global.yoho.API;
8 8
9 -const getProductBannerAsync = (pid, clientType) => {  
10 - clientType = clientType || 'web'; 9 +const getProductBannerAsync = (pid) => {
11 return api.get('', { 10 return api.get('', {
12 method: 'web.productBanner.data', 11 method: 'web.productBanner.data',
13 - product_id: pid,  
14 - client_type: clientType 12 + product_id: pid
15 }); 13 });
16 14
17 }; 15 };
@@ -42,7 +42,7 @@ const _getProductAdditionInfoAsync = (data) => { @@ -42,7 +42,7 @@ const _getProductAdditionInfoAsync = (data) => {
42 42
43 // 获取相关数据 43 // 获取相关数据
44 let promiseData = [ 44 let promiseData = [
45 - productAPI.getProductBannerAsync(productId, 'web'), 45 + productAPI.getProductBannerAsync(productId),
46 productAPI.sizeInfoAsync(skn), 46 productAPI.sizeInfoAsync(skn),
47 productAPI.getProductComfortAsync(productId), 47 productAPI.getProductComfortAsync(productId),
48 productAPI.getProductModelCardAsync(productId), 48 productAPI.getProductModelCardAsync(productId),
@@ -178,7 +178,7 @@ const _getVipDataByProductBaseInfo = (data, vipLevel, uid) => { @@ -178,7 +178,7 @@ const _getVipDataByProductBaseInfo = (data, vipLevel, uid) => {
178 const _getProductActivityBanner = () => { 178 const _getProductActivityBanner = () => {
179 let data = _getCacheDataByName('ItemData::getProductBanner'); 179 let data = _getCacheDataByName('ItemData::getProductBanner');
180 180
181 - if (_.get(data, 'code', 400) !== 200 || !_.get(data, 'data.bannerImg')) { 181 + if (_.isElement(data) || _.get(data, 'code', 400) !== 200 || !_.get(data, 'data.bannerImg')) {
182 return {}; 182 return {};
183 } 183 }
184 184
@@ -251,7 +251,7 @@ const _getBrandDataByProductBaseInfo = (data) => { @@ -251,7 +251,7 @@ const _getBrandDataByProductBaseInfo = (data) => {
251 let bannerInfo = null; 251 let bannerInfo = null;
252 let result = _getCacheDataByName('BrandData::getBannerInfo'); 252 let result = _getCacheDataByName('BrandData::getBannerInfo');
253 253
254 - if (!result) { 254 + if (_.isEmpty(result)) {
255 return {}; 255 return {};
256 } 256 }
257 257
@@ -755,23 +755,23 @@ const _detailDataPkg = (origin, uid, vipLevel) => { @@ -755,23 +755,23 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
755 if (domainBrand.type && domainBrand.shopId) { 755 if (domainBrand.type && domainBrand.shopId) {
756 switch (parseInt(domainBrand.type, 10)) { 756 switch (parseInt(domainBrand.type, 10)) {
757 case 1: 757 case 1:
758 - { 758 + {
759 // 多品店不显示 759 // 多品店不显示
760 - banner = [];  
761 - break;  
762 - } 760 + banner = [];
  761 + break;
  762 + }
763 case 2: 763 case 2:
764 - { 764 + {
765 // 单品店显示新版的店铺banner 765 // 单品店显示新版的店铺banner
766 - let basisData = yield shopService.basisTemplateAsync(domainBrand.shopId); 766 + let basisData = yield shopService.basisTemplateAsync(domainBrand.shopId);
767 767
768 - banner.bgImg = basisData.shopTopBanner.banner || banner.bgImg;  
769 - break;  
770 - } 768 + banner.bgImg = basisData.shopTopBanner.banner || banner.bgImg;
  769 + break;
  770 + }
771 default: 771 default:
772 - {  
773 - break;  
774 - } 772 + {
  773 + break;
  774 + }
775 } 775 }
776 } 776 }
777 } 777 }
@@ -797,7 +797,7 @@ const _getProductComfort = () => { @@ -797,7 +797,7 @@ const _getProductComfort = () => {
797 let result = []; 797 let result = [];
798 let comfort = _getCacheDataByName('ItemData::getProductComfort'); 798 let comfort = _getCacheDataByName('ItemData::getProductComfort');
799 799
800 - if (!comfort || !comfort.data) { 800 + if (_.isEmpty(comfort) || !comfort || !comfort.data) {
801 return result; 801 return result;
802 } 802 }
803 803
@@ -1024,7 +1024,7 @@ const _getSizeData = (sizeInfo) => { @@ -1024,7 +1024,7 @@ const _getSizeData = (sizeInfo) => {
1024 const _getProductModelCard = () => { 1024 const _getProductModelCard = () => {
1025 let data = _getCacheDataByName('ItemData::getProductModelCard'); 1025 let data = _getCacheDataByName('ItemData::getProductModelCard');
1026 1026
1027 - if (!data || _.get(data, 'code', 400) !== 200) { 1027 + if (_.isEmpty(data) || !data || _.get(data, 'code', 400) !== 200) {
1028 return []; 1028 return [];
1029 } 1029 }
1030 1030
@@ -1329,6 +1329,16 @@ const _getSeoByGoodsInfo = function(goodsInfo, navs) { @@ -1329,6 +1329,16 @@ const _getSeoByGoodsInfo = function(goodsInfo, navs) {
1329 }; 1329 };
1330 }; 1330 };
1331 1331
  1332 +// 清除缓存
  1333 +const _dispose = () => {
  1334 + cachedRequestData['ItemData::getProductBanner'] = {};
  1335 + cachedRequestData['ItemData::sizeInfo'] = {};
  1336 + cachedRequestData['ItemData::getProductComfort'] = {};
  1337 + cachedRequestData['ItemData::getProductModelCard'] = {};
  1338 + cachedRequestData['ItemData::getProductModelTry'] = {};
  1339 + cachedRequestData['BrandData::getBannerInfo'] = {};
  1340 +};
  1341 +
1332 /** 1342 /**
1333 * 获取某一个商品详情主页面 1343 * 获取某一个商品详情主页面
1334 */ 1344 */
@@ -1380,11 +1390,11 @@ const showMainAsync = (data) => { @@ -1380,11 +1390,11 @@ const showMainAsync = (data) => {
1380 ); 1390 );
1381 1391
1382 result.detail.latestWalk = 5; 1392 result.detail.latestWalk = 5;
  1393 +
1383 return result; 1394 return result;
1384 - })(); 1395 + })().finally(_dispose);
1385 }; 1396 };
1386 1397
1387 -  
1388 module.exports = { 1398 module.exports = {
1389 indexCommentAsync: commentService.indexAsync, // 获取评论列表 1399 indexCommentAsync: commentService.indexAsync, // 获取评论列表
1390 getShareOrderListAsync: commentService.getShareOrderListAsync, // 获取评论列表 1400 getShareOrderListAsync: commentService.getShareOrderListAsync, // 获取评论列表