Em 14-05-2012 18:22, Andrew White escreveu:
On 14 May 2012, at 14:06, Rodrigo Rosenfeld Rosas wrote:

I'm not sure what you expect Rails to do here - how does it know to fetch the 
JSON cached version if you're relying on the content_type being set by the 
render? The whole point of action caching is to avoid calling render.
I was expecting the relevant headers to be cached alongside with the body 
content of the response.
That's a longstanding issue - you may want to look at using HTTP caching 
instead which does cache headers. Rails 3.2 is pre-configured with Rack::Cache 
- try removing the action caching code from your controller and look at the API 
docs for stale?, fresh_when? and expires_in. See also the Rails Guide on 
caching:

http://guides.rubyonrails.org/caching_with_rails.html#conditional-get-support

This is different and less useful for my application. That is because I'd like to fill the cache only in the first access no matter which client did request it first. Until that action is expired, only the first client should notice the delay in the first access. All other clients should benefit from this first access as well.

Would you mind explain why it is hard to store the headers alongside with the body in the caches_page mechanism?

We could certainly consider whether :format =>   :json or :format =>   [:html, 
:json] would restrict it to those formats (i.e. setup :constraints and :defaults 
automatically), however that would have to be with :format in the path as you can't turn 
it off without :format =>   false. Please open an issue to consider this further.
Thanks! I'll try to figure it out an API that could allow an unformatted URL 
before opening the issue. If I can't come to any suggestion I'll open the issue 
with the API you've just mentioned.

Wouldn't it be possible that "get '/products', format: :json" responded to both 
'/products' and '/products.json' when a single format is given instead of an array? Of 
course I mean that action caching should also use the same correct content-type in the 
response for both URLs.
You can do that now using an empty option in your regexp:

get '/products' =>  'products#index', :format =>  /|json/

This will match /products and /products.json

Yeah, but then if I accessed /products in a cached action the returned content-type would be text/html, right?

Thanks for your support,
Rodrigo.

--
You received this message because you are subscribed to the Google Groups "Ruby on 
Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to