5

我是否这样做:

head 302

或者

head 307

或者

redirect_to

调用相同的控制器动作

response.headers['Cache-Control'] = "public, max-age=86400"

没有效果。Rails 发送:

Cache-Control: no-cache

无论。我需要发送 Cache-Control 标头来指示边缘缓存为重定向服务一天。这可能吗?

4

4 回答 4

12

您不能将 Cache-Control 直接设置到标头中(现在?),因为您需要修改 response.cache_control 对象(因为稍后将使用它来设置 Cache-Control 标头)。

幸运的是, expires_in 方法会为您解决这个问题:

expires_in 1.day, :public => true

在此处查看更多信息:http: //apidock.com/rails/ActionController/ConditionalGet/expires_in

于 2011-06-15T03:32:33.640 回答
1

尝试改用这个

response.headers['Cache-Control'] = 'public, max-age=300'

并确保您处于生产模式。Rails 不会在开发中缓存。

于 2011-06-05T23:07:15.090 回答
1

使用 Rails 5,您可以做到

response.cache_control = 'public, max-age=86400'
于 2016-03-17T16:30:38.880 回答
0
. I need to send the Cache-Control header to instruct an edge cache to serve the redirect for a day.

这怎么可能 ?在临时重定向的情况下,浏览器将始终尝试首先获取原始 url,然后在重定向时他们将尝试其他 url,如果缓存在代理上,则可以从那里提供服务。但是再次浏览器仍然会与您的服务器进行首次联系。

于 2011-06-03T22:49:54.420 回答