有几个 S.O.诸如此类的问题:
- Rails ( set_no_cache method) Cannot disable browser caching in Safari and Opera
- How to prevent browser page caching in Rails
但无论我做什么,我覆盖的内容仍然会得到 header (FireFox、Chrome、curl -V
、...任何浏览器)
缓存控制:必须重新验证,私有(private),max-age=0
我试过了
class ApplicationsController < ActionController::Base
before_filter :no_store_cache
after_filter :no_store_cache
def no_store_cache
response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = '-1'
end
end
我尝试直接在 ActionController::Base
( https://github.com/equivalent/no_cache_control.git ) 上调用此回调
我尝试挖掘rack-cache
中间件覆盖的东西试图强制执行 header
我创建了自己的中间件,该中间件覆盖 header['Cache-Control']
。
没有任何效果
最佳答案
使用 Rails 3.2 gem no_cache_control
仅当 Rails 应用程序在生产模式下启动时才有效。可以通过在生产模式下启动您的应用程序来测试这一点:
rails s -e 生产
注意:确保您的 database.yml
指向对生产环境有效的某个位置。
关于ruby-on-rails - 如何在 Rails 3.2.20 中强制 Cache-Control 不存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26994714/