如何强制Cache-Control在Rails 3.2.20中不存储 [英] how to force Cache-Control to no-store in rails 3.2.20

查看:73
本文介绍了如何强制Cache-Control在Rails 3.2.20中不存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有几个S.O.像这样的问题:

There are several S.O. questions on this like:

  • Rails ( set_no_cache method) Cannot disable browser caching in Safari and Opera
  • How to prevent browser page caching in Rails

但是我没有做任何事情,我覆盖的内容仍然是标题(FireFox,Chrome, curl -V ,...任何浏览器)

But no mater what I do, what I override I'm still getting header (FireFox, Chrome, curl -V, ...any browser)


缓存控制:必须重新验证,私有,最大年龄= 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 中间件优先的东西,试图执行标头

I Tried digging in rack-cache middle-ware overriding stuff trying to enforce the header

我创建了自己的中间件,该中间件覆盖了 header ['Cache-Control']

I've created my own middleware that was overriding header['Cache-Control'].

无济于事

推荐答案

使用Rails 3.2 gem no_cache_control 仅在以生产模式启动rails应用程序时有效。可以通过以下方式在生产模式下启动您的应用程序进行测试:

With Rails 3.2 the gem no_cache_control only works when the rails app is booted in production mode. Can test this by booting your app in production mode with:

rails s -e production

注意:确保您的 database.yml 指向对生产环境有效的位置。

Note: make sure you have your database.yml pointing somewhere valid for the production environment.

这篇关于如何强制Cache-Control在Rails 3.2.20中不存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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