Hi, I''m new to fragment caching, and was wondering the best way to do it for a dynamically generated page. I have been working off of the "Agile Web Development with Rails" book, but it''s rather brief on fragment caching. For example, suppose you have a list of manufacturers and each of which has many products. Here is how I would implement the caching, but I''m not clear if it will work, or if there''s a cleaner, less clunky of doing it: Product Controller: def list @mid = params[:manufacturer_id] if @mid.nil? @mid = "all" unless read_fragment(:action => ''list'', :mid => "all") @products = Product.find(:all) end else unless read_fragment(;action => ''list'', :mid => @mid.to_s) @products = Product.find_by_manufacturer_id(@mid) end end end View (list.rhtml) <% cache(:action =>''list'', :mid => @mid) do %> <ul> <% for p in @products %> <li><%= p.name %></li> <% end %> </ul> <% end > Any suggestions or advice on a better way to to go about doing this would be much appreciated. Thanks. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jay, I''m fairly new to Rails too, but the code looks fine. There are no doubt more Ruby ways of writing it. One thing. Doesn''t the cache need to be expired when a manufacture updates? Xin -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Xin Zheng wrote:> Jay, > > I''m fairly new to Rails too, but the code looks fine. There are no doubt > more Ruby ways of writing it. > > One thing. Doesn''t the cache need to be expired when a manufacture > updates? > > XinYes, I didn''t include the code for putting in sweepers to expire the cache when the manufacturer/product is updated. Does anyone have any recommendations for production-ready plugins that make this simpler? I''ve been bouncing around the various plugin sites, and haven''t found one that seems to make this as easy as it should be. One promising one is this one, but I don''t think I would call it production-ready, as it looks like it was released *yesterday*: http://blog.overlay.tv/articles/2007/06/16/intelligent_fragment_cache -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---