I have a page that requires a lot of DB access to create a section of it, but that section does not change very often. I know how to cache the fragment in the view, but the db is still accessed in the controller. I watched the railscasts on fragment caching and he does it by moving the logic to the model. Is that the only way to do it? The part of the page that changes on every display is the advertising so I can not cache the entire page. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
rubyguy-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org
2009-Mar-17 07:06 UTC
Re: Caching in Rails
On 17 Mar., 07:56, Don French <dhf0...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a page that requires a lot of DB access to create a section of > it, but that section does not change very often. I know how to cache > the fragment in the view, but the db is still accessed in the > controller. I watched the railscasts on fragment caching and he does > it by moving the logic to the model. Is that the only way to do it? > The part of the page that changes on every display is the advertising > so I can not cache the entire page.You can use the #fragment_exists? method in your controller action. This allows you to avoid querying the database if it''s not neseccary. def action unless fragment_exists? "fragment" # Execute SQL here... end end -- Cheers, David Knorr http://twitter.com/rubyguy --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---