On Oct 21, 2005, at 12:17 AM, Gary Lin wrote:
> Hi,
>
> I''m wondering, how to cache the component result?
> I have a page which is composited by several components.
> For example, I have a blog controller, which is to display both
> category and article list with different page number.
>
> in BlogController:
> def list
> @category_list = render_component_as_string(:controller =>
> ''category'', :action => ''list'', :id
=> 1)
> @article_list = render_component_as_string(:controller =>
> ''article'', :action => ''list'', :id
=> 2)
> end
>
> in BlogView:
> <%= @contegory_list %>
> <%= @article_list %>
>
> 0) before adding any cache
> I got
> [category list... page 1]
> [article list ... page 2]
>
> 1) caches_page
> If I add caches_page for category::list, article::list
> then I got only
> [article list page2]
>
> category list is missing.
>
> and it will create cache file likes blog/list.rhtml
> this is not what I want.
>
> 2) caches_action
> if I add caches_action for category::list, article::list
> this time I got
> [category list page 1]
> [category list page 1]
> not what I want again.
>
> 3) I use <% cache do %> for fragment cache
> but I got the same result of 2)
>
> Any advise how to cache the render_component_as_string result ?
> Thanks.
>
> Gary
Gary-
You might want to try to move those render_component_as_string
calls into the view where you are using them and change them to just
plain render_component calls. I have pages that render many
components from the views and cache them with normal caches_page and
it works great.
Cheers-
-Ezra Zygmuntowicz
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org