configurationsails.js不caching响应

我有一个应用程序node.js使用sails.js作为框架。 为了向用户显示信息,我已经实现了一些.ejs文件。
当使用应用程序菜单中的链接进行导航时,我收到“304 – Nod Modified”响应。 另外,在响应的标题中,我看到了EtagIf-None-MatchExpires
在阅读了一些文章后,我在customMiddleware函数的/ config / express.js文件中添加了“app.disable('etag')”语句,etag和if-none-match不再发送。
无论如何,现在我看不到任何要求服务器(只是第一个作出)访问不同的网页(甚至没有304响应)。
我怎么能告诉sails.js停止caching我的网页?

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

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

看来,添加下面的代码解决了我的问题:

 res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate'); res.header('Expires', '-1'); res.header('Pragma', 'no-cache'); 

这些行应该包含在/ config / express.js文件的customMiddleware函数中。

如果有更清晰的方法可以达到同样的结果,请回复。