Forum: Ruby on Rails Rails 2.3.8 Action Caching without layout (ajax and non-ajax requests)

8fa794fe18c3b70661cd21ddd86b79ab?d=identicon&s=25 nico (Guest)
on 2010-11-30 15:32
(Received via mailing list)
Hi there,

I'm using Action Caching with Rails 2.3.8 on Heroku with Memcached
(via Dalli Gem).

Without the layout parameter Action Caching works fine. However, as
soon as I add layout => false I get problems: Normal non-ajax requests
are cached fine, without the layout, as expected. But ajax requests
are not properly cached: I get cache misses all the time. Then, when I
log in to my app neither normal, nor ajax requests are cached at all.

I also tried to set :layout => Proc.new { |c| c.request.xhr? }
When I do that ajax and normal requests are properly cached (no matter
if logged out or logged in)
but normal requests also cache the layout. Seems odd to me as normal
requests should have :layout => false.
I'm trying to debug this for hours now, but I haven't got a clue
what's going on so far. What especially confuses me
is that the logged in state of my app apparently has an influence on
the caching behaviour.

Here is my full caching call (for the case of layout => false):

[code]caches_action :index, :layout => false,
                      :cache_path => Proc.new { |c|
c.params.clone.delete_if { |k,v| ['authenticity_token'].include?
(k) }.merge(:xhr => c.request.xhr? ? 't' : 'f') }[/code]

I'd greatly appreciate any help on this!

Nico
8fa794fe18c3b70661cd21ddd86b79ab?d=identicon&s=25 nico (Guest)
on 2010-11-30 21:59
(Received via mailing list)
Okay, I debugged a bit more and found out what the problem is
(at least when locally in development environment). Inside the action
cache content_for_layout
is called to get the content to be cached if layout is set to false.
This causes
my ajax requests to be not cached because content_for_layout returns
nil as
I don't render the layout with ajax calls, only a partial. So I do
need to set
layout to true for ajax calls. However I can't do that the way I tried
to, as
the layout param doesn't accept a Proc. So I overwrote part of the
ActionCacheFilter class
to test the layout for a call method and call it if present. That
works great locally!
However, in production on Heroku with Memcached it still won't work
properly.
Ajax calls are not cached.
8fa794fe18c3b70661cd21ddd86b79ab?d=identicon&s=25 nico (Guest)
on 2010-12-01 09:26
(Received via mailing list)
Okay, works fine now! I slightly changed the way I overwrote the
ActionCacheFilter.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.