Authored by 陈峰

Merge branch 'feature/fix' into 'release/6.8.7'

add max age



See merge request !16
... ... @@ -73,11 +73,6 @@ const getCacheKey = (urlPath, cacheKey = '') => {
const render = (route) => {
return async(req, res, next) => {
try {
res.set({
'Cache-Control': 'no-cache',
Pragma: 'no-cache',
Expires: (new Date(1900, 0, 1, 0, 0, 0, 0)).toUTCString()
});
res.setHeader('X-YOHO-Version', pkg.version);
const isDegrade = _.get(req.app.locals.wap, 'webapp.degrade', false);
... ... @@ -89,12 +84,21 @@ const render = (route) => {
if (config.useCache && route.cache && ck) {
const html = await redis.getAsync(ck);
res.set({
'Cache-Control': 'max-age=' + route.cacheTime || 60
});
if (html) {
logger.debug(`cached ${req.url}`);
res.setHeader('X-YOHO-Cached', 'HIT');
return res.send(html);
}
res.setHeader('X-YOHO-Cached', 'MISS');
} else {
res.set({
'Cache-Control': 'no-cache',
Pragma: 'no-cache',
Expires: (new Date(1900, 0, 1, 0, 0, 0, 0)).toUTCString()
});
}
let context = getContext(req);
... ... @@ -124,12 +128,21 @@ const devRender = (route) => {
if (config.useCache && route.cache && ck) {
const html = await redis.getAsync(ck);
res.set({
'Cache-Control': 'max-age=' + route.cacheTime || 60
});
if (html) {
logger.debug(`cached ${req.url}`);
res.setHeader('X-YOHO-Cached', 'HIT');
return res.send(html);
}
res.setHeader('X-YOHO-Cached', 'MISS');
} else {
res.set({
'Cache-Control': 'no-cache',
Pragma: 'no-cache',
Expires: (new Date(1900, 0, 1, 0, 0, 0, 0)).toUTCString()
});
}
let context = getContext(req);
... ...