设置 Cache-Control header 作为回应

Set Cache-Control header in response

我正在为 API 应用程序使用 Rails (v3.2.21) 并尝试在我的响应中设置 "Cache-Control" header 以便我的客户端应用程序可以缓存它们。但是,实际响应中的 header 值仍在使用默认值(使用 Chrome 中的 Advanced Rest Client 插件进行检查)。

从 Googlage 看来,expires_in 方法是执行此操作的方法:

expires_in 3.hours, :public => true

但是,当我向资源发出请求时,它总是 returns(默认值?):

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

当我在 expires_in 之后执行 binding.pry 并检查 response.headers 时,它是空的...似乎也是错误的。

我在我的控制器中 before_filter 中执行上述操作,并且在我调用 render 以 return 我的回复之前也尝试过。

我应该补充一点,我尝试使用 response.headers["CacheControl"] = "blah" 手动设置 "Cache-Control" header,但这也不起作用,我在别处读到 Rails 无论如何都不允许这样做。

有人知道我在这里做错了什么吗?

这实际上归因于我在应用程序中的一些其他配置,这些配置阻止了缓存的发生(特别是 Bullet.disable_browser_cache 设置,这对开发环境是正确的)。将此设置为 false 意味着缓存正常工作。