Authored by 周少峰

Merge branch 'gray'

@@ -218,12 +218,19 @@ const getHeaderNavAsync = () => { @@ -218,12 +218,19 @@ const getHeaderNavAsync = () => {
218 * @param {String} 频道类型 218 * @param {String} 频道类型
219 * @return {promise} 219 * @return {promise}
220 */ 220 */
221 -let cacheHeaderHtml = {}; 221 +const cacheHeaderHtml = {
  222 + boys: [],
  223 + girls: [],
  224 + kids: [],
  225 + lifestyle: []
  226 +};
  227 +
  228 +const THIRTY_MINUTES = 1000 * 60 * 10;
222 229
223 async function requestHeaderData(type) { 230 async function requestHeaderData(type) {
224 let resData = {}; 231 let resData = {};
225 232
226 - if (_.isEmpty(cacheHeaderHtml[type])) { 233 + if (_.isEmpty(cacheHeaderHtml[type][0]) || ((new Date() - cacheHeaderHtml[type][1]) > THIRTY_MINUTES)) {
227 let channelNum = (function() { 234 let channelNum = (function() {
228 switch (type) { 235 switch (type) {
229 case 'boys': 236 case 'boys':
@@ -270,17 +277,12 @@ async function requestHeaderData(type) { @@ -270,17 +277,12 @@ async function requestHeaderData(type) {
270 cacheHeaderHtml[type] = resData; 277 cacheHeaderHtml[type] = resData;
271 } 278 }
272 } else { 279 } else {
273 - resData = cacheHeaderHtml[type]; 280 + resData = cacheHeaderHtml[type][0];
274 } 281 }
275 282
276 return Promise.resolve({headerData: resData}); 283 return Promise.resolve({headerData: resData});
277 } 284 }
278 285
279 -  
280 -setInterval(function() {  
281 - cacheHeaderHtml = {};  
282 -}, 60 * 10 * 1000);  
283 -  
284 module.exports = { 286 module.exports = {
285 requestHeaderData 287 requestHeaderData
286 }; 288 };