Action caching: how to prevent cached request being wrapped with layout when originally rendered with :layout => false

Hi all,

I've run into a problem with action caching in Rails 3.2.1 and am wondering if anyone can shed some light on the situation.

We are using caches_action with :layout => false for the #show action on our controller.

The code for the action sometimes renders with the layout, and sometimes without, eg:

if request.xhr?   render :action => "different_action", :layout => false else   # render with layout end

Subsequent cached requests to the code path where we originally rendered :layout => false are now rendered with the layout. It seems what Rails is doing is seeing that you didn't cache the layout originally, and therefore wrapping each subsequent request with the standard layout. What we want is for the layout not to be rendered.

This caching was (allegedly) working correctly in Rails 2.3, but I haven't looked into the old ActionController caching code yet to see how/why.

How should this sort of action be cached so that subsequent requests don't wrap the cached action body in the layout?

Cheers, -Jonathan.