Vic*_*tor 5 caching node.js sails.js
我使用sails.js作为框架在node.js上有一个应用程序.为了向用户显示信息,我实现了一些.ejs文件.
当使用应用程序菜单中的链接导航时,我收到"304 - Nod Modified"响应.此外,在响应的标题内,我看到Etag,If-None-Match或Expires.
在阅读了一些帖子后,我在customMiddleware函数的/ config/express.js文件中添加了"app.disable('etag')"语句,并且不再发送etag和if-none-match.
无论如何,现在我在访问不同页面时看不到对服务器的任何请求(只是第一个请求)(甚至不是304响应).
如何告诉sails.js停止缓存我的页面?
小智 11
您可以将其添加到策略中,然后将其应用于您想要的特定页面/请求 - 如果您不想为整个应用程序设置此项.
/api/policies/nocache.js:
/**
* Sets no-cache header in response.
*/
module.exports = function (req, res, next) {
sails.log.info("Applying disable cache policy");
res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
res.header('Expires', '-1');
res.header('Pragma', 'no-cache');
next();
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4873 次 |
| 最近记录: |