如何在 Rails 3.2.20 中强制 Cache-Control 不存储

2024-01-10

有几个S.O.诸如此类的问题:

  • Rails(set_no_cache方法)无法禁用Safari和Opera中的浏览器缓存 https://stackoverflow.com/questions/10744169/rails-set-no-cache-method-cannot-disable-browser-caching-in-safari-and-opera
  • 如何在 Rails 中防止浏览器页面缓存 https://stackoverflow.com/questions/711418/how-to-prevent-browser-page-caching-in-rails

但无论我做什么,我覆盖什么,我仍然会得到标题(FireFox,Chrome,curl -V,...任何浏览器)

Cache-Control: must-revalidate, private, max-age=0

I tried

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 https://github.com/equivalent/no_cache_control.git )

我尝试挖掘rack-cache中间件覆盖试图强制标头的东西

我创建了自己的中间件,这是最重要的header['Cache-Control'].

没有任何作用


使用 Rails 3.2 宝石no_cache_control https://github.com/equivalent/no_cache_control仅当 Rails 应用程序在生产模式下启动时才有效。可以通过在生产模式下启动您的应用程序来测试这一点:

rails s -e production

注意:确保你有你的database.yml指向对生产环境有效的某个地方。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 Rails 3.2.20 中强制 Cache-Control 不存储 的相关文章

随机推荐