Reputation: 536
I'm using Rails (v3.2.21) for an API application and trying to set the "Cache-Control" header in my responses so that my client app can cache them. However, the header values on the actual response are still using the default values (checked using Advanced Rest Client plugin in Chrome).
From Googlage, it seems that the expires_in
method is the way to do this:
expires_in 3.hours, :public => true
However, when I make a request to the resource, it always returns (the default?):
Cache-Control: must-revalidate, no-cache, no-store, private, max-age=0
When I do a binding.pry right after the expires_in
and check response.headers
, it is empty... seems wrong too.
I'm doing the above in before_filter
in my controller, and have also tried right before I call render
to return my response.
I should add that I've tried to set the "Cache-Control" header manually using response.headers["CacheControl"] = "blah"
but that doesn't work either and I've read elsewhere that Rails doesn't allow this anyway.
Does anyone have any ideas on what I am doing wrong here?
Upvotes: 4
Views: 4548
Reputation: 536
This was actually down to some other config that I had in the app which was preventing caching from happening (specifically the Bullet.disable_browser_cache
setting which was true for development environments). Setting this to false meant that caching worked properly.
Upvotes: 3