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

标签 ruby-on-rails ruby-on-rails-3 cache-control

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

但无论我做什么,我覆盖的内容仍然会得到 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/

相关文章:

ruby-on-rails - rails 3 : Predictive filtering (faceted navigation)

ruby-on-rails-3 - 警告 : else without rescue is useless?

java - 使用 web.xml 和 setMaxInactiveInterval 设置 session 超时之间的区别

java - 如何在 Spring Boot 中将 Cache-Control header 添加到静态资源?

IIS7.5 OutputCacheModule 内核缓存 'public' 忽略 URL

ruby-on-rails - heroku scale web=1 返回 "no such type as web"

ruby-on-rails - 在 Rails 中创建制表符分隔的 ASCII 文件

ruby-on-rails - Vbox 和 Rails 上的 Ubuntu—— "Please install tilt-1.3.3"

mysql - habtm混淆..逻辑查询

ruby-on-rails - Ruby on Rails form_with 未显示错误,卡在服务器端