配置sails.js不缓存响应 [英] Configure sails.js not to cache the response

查看:54
本文介绍了配置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停止缓存我的页面?

I have an application on node.js using sails.js as a framework. For displaying the informations to the user I have implemented some .ejs files.
When navigating using links within the app menu, I receive a "304 - Nod Modified" response. Also, within headers in the response I see Etag, If-None-Match or Expires.
After reading some posts, I have added the "app.disable('etag')" statement within /config/express.js file in the customMiddleware function and etag and if-none-match are not sent anymore.
Anyway, now I do not see any request made to the server (just the first one is made) when accessing different pages (not even 304 response).
How can I tell sails.js to stop caching my pages?

推荐答案

您可以添加而是将其应用于策略,然后将其应用于所需的特定页面/请求-如果您不想为整个应用程序设置此参数。

You can add this to a policy instead and then just apply it to the specific pages/requests you want - if you do not want to set this for the entire application.

/ api / policy / nocache.js:

/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();
};

这篇关于配置sails.js不缓存响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆