...
|
...
|
@@ -3,12 +3,10 @@ |
|
|
|
|
|
const path = require('path');
|
|
|
const cachePage = require('../../config/cache');
|
|
|
const logger = global.yoho.logger;
|
|
|
|
|
|
module.exports = () => {
|
|
|
return (req, res, next) => {
|
|
|
if (req.get('X-Requested-With') === 'XMLHttpRequest') {
|
|
|
res.set('Cache-Control', 'no-cache');
|
|
|
}
|
|
|
|
|
|
function onRender() {
|
|
|
let route = req.route ? req.route.path : '';
|
...
|
...
|
@@ -17,6 +15,8 @@ module.exports = () => { |
|
|
|
|
|
req.app.set('etag', false);
|
|
|
|
|
|
logger.debug(`route: ${key} cache = ${cachePage[key]}`);
|
|
|
|
|
|
// 如果存在cache配置,并且业务代码中没有设置
|
|
|
if (cachePage[key] && res.get('Cache-Control') !== 'no-cache') {
|
|
|
res.set({
|
...
|
...
|
@@ -24,6 +24,8 @@ module.exports = () => { |
|
|
});
|
|
|
res.removeHeader('Pragma');
|
|
|
res.removeHeader('Expires');
|
|
|
} else if (req.get('X-Requested-With') === 'XMLHttpRequest') {
|
|
|
res.set('Cache-Control', 'no-cache');
|
|
|
} else {
|
|
|
res.set({
|
|
|
'Cache-Control': 'no-cache',
|
...
|
...
|
|