开发者

Overriding rails Cache-Control header on redirect

Whether I do:

head 302

or

head 307

or

redirect_to

calls in the same controller action to

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

have no effect. Rails sen开发者_开发技巧ds:

Cache-Control: no-cache

no matter what. I need to send the Cache-Control header to instruct an edge cache to serve the redirect for a day. Is this possible?


You can't set Cache-Control directly into the headers (anymore?), as you need to modify the response.cache_control object (since it will be used to set the Cache-Control header later).

Luckily, the expires_in method takes care of this for you:

expires_in 1.day, :public => true

See more here: http://apidock.com/rails/ActionController/ConditionalGet/expires_in


Try using this instead

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

and make sure your in production mode. Rails wont cache in development.


With Rails 5 you can do

response.cache_control = 'public, max-age=86400'


. I need to send the Cache-Control header to instruct an edge cache to serve the redirect for a day.

How is this possible ? in case of temp redirect , browsers will always try to get original url first and on redirect they will try other url,which if cached on proxies can be served from there. But again browser will still make first contact with your server.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜