Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yohobuywap-node
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
姜枫
8 years ago
Commit
2ac5835987a51bff32a9730ce04256376ad3c96d
1 parent
cc6ec537
support ajax cache
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
7 deletions
apps/activity/index.js
doraemon/middleware/page-cache.js
apps/activity/index.js
View file @
2ac5835
...
...
@@ -17,12 +17,9 @@ app.on('mount', function(parent) {
delete
parent
.
locals
.
settings
;
// 不继承父 App 的设置
Object
.
assign
(
app
.
locals
,
parent
.
locals
);
});
app
.
set
(
'views'
,
path
.
join
(
__dirname
,
'views/action'
));
app
.
use
(
global
.
yoho
.
hbs
({
extname
:
'.hbs'
,
defaultLayout
:
'layout'
,
layoutsDir
:
doraemon
,
partialsDir
:
path
.
join
(
__dirname
,
'views/partial'
,
`
$
{
doraemon
}
/partial`
)
,
partialsDir
:
path
.
join
(
__dirname
,
'views/partial'
),
views
:
path
.
join
(
__dirname
,
'views/action'
),
helpers
:
Object
.
assign
({},
global
.
yoho
.
helpers
,
helpers
)
}));
...
...
doraemon/middleware/page-cache.js
View file @
2ac5835
...
...
@@ -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'
,
...
...
Please
register
or
login
to post a comment