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