My scenario: Master layout for all pages. Main content in right pane, nav bar content (persists on all pages) in left pane. I handle the rendering of pages by putting @content_for_layout in its place, and using render_component( :controller => ''foo'', :action => ''bar'' ) for rendering different components of the left pane/nav bar. However, these "components" do not reside in /app/components, but are simply actions under app/controllers/foo_controller.rb If I turn on page caching for action ''bar'', and request my page, the action ''bar'' is cached, but as /index.html. In fact, all components (there are 4) in this left pane are cached in turn as /index.html. Of course, when I reload the page, this cache is not used, but the action ''bar'' is cached as /index.html again. If I specifically call www.mydomain.com/foo/bar, then the page is cached as expected. But loading the normal page does not see this cache, and still does a full call to the action and caches the action as /index.html. Is this a bug? Or is there another, better, (aka working) way of doing this? Matt
Update: Giving this some more thought, I realize that page caching works by caching the entire page, which Apache then uses directly completely skipping the rails app. Therefore, page caching will flat not work under the above circumstances. So, instead, I tried action level caching. At first, I thought this would do the trick. The component was cached, and that cache was used on successive calls to the page. Unfortunately, this will only work if I ever action cache 1 component in the entire application... because the component is cached as "www.mydomain.com/" So, every single action which I call specify as having action caching will cache as www.mydomain.com/ if called as a component. So, if I action cache 2 of these which I am calling render component on, I actually end up with a page rendering one of the components 2 times (whichever one was last called, and thus last cached). So, in other words, I''m still stuck. I''m trying to avoid fragment caching, because I don''t want the DB queried ... but I''m not sure I have any other options. Matt
> I''m trying to avoid fragment caching, because I don''t want the DB > queried ... but I''m not sure I have any other options.Just a thought, why not try fragment caching in the layout? <% cache(:action => "list", :action_suffix => "all_topics") do -%> <%= render_component %> <% end -%> When the cache is empty, it renders the component and queries the DB. -- rick http://techno-weenie.net
*snip from direct response to Rick*> I''m trying to avoid fragment caching for in this particular instance, > since fragment caching still executes all database queries in the > action.> It may be the only solution for the time being. I''m not actually sure > it will work, because the action caching looks in the wrong place for > the cache, so why would fragment caching look in the right place. > I''ll try it just out of curiousity, and report back.Hmm, now this is very interesting, and not what I expected. My understanding of fragment caching was that the action is still called and all operations in that action in the controller are processed, including all DB calls. And this is indeed the behaviour we see if one were to have a fragment cache in /bar/foo and we directley called bar/foo ... that is, all DB queries in foo() are called. However, this does not seem to be the case if I call the action using render_component from within my layout. All my log says is that a fragment was hit and rendered. And, as I type this out, it is becoming clear to me. The fragment being cached is the *result* of the render_component call. If the fragment where sitting *inside* the action on the component call, instead of outside, the action would still be called. When rails processes the request, it sees a cache fragment -- it has no idea there was a whole new action call inside that fragment, becuase once it sees it has a fragment cache available, it drops it in its place. Perfect. This is exactly what I needed. Thanks for the help! Matt