I seem to have @facilities = Facility.find(:all) in a lot of places in my application and my facilities model data rarely changes. How can I cache it so that I don''t have to hit the DB each time? Craig --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Craig White wrote:> I seem to have @facilities = Facility.find(:all) in a lot of places in > my application and my facilities model data rarely changes. How can I > cache it so that I don''t have to hit the DB each time?class Facility < ActiveRecord::Base after_save {@@all_facilities = nil} def self.all_facilities @@all_facilities ||= self.find(:all) end end @facilities = Facility.all_facilities -- 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 -~----------~----~----~----~------~----~------~--~---
On Wed, 2008-03-26 at 14:43 +0100, Mark Bush wrote:> Craig White wrote: > > I seem to have @facilities = Facility.find(:all) in a lot of places in > > my application and my facilities model data rarely changes. How can I > > cache it so that I don''t have to hit the DB each time? > > class Facility < ActiveRecord::Base > after_save {@@all_facilities = nil} > def self.all_facilities > @@all_facilities ||= self.find(:all) > end > end > > > @facilities = Facility.all_facilities---- thanks - made it simple...I likee Craig --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> </head> <body bgcolor="#ffffff" text="#000000"> Craig White wrote: <blockquote cite="mid:1206539334.25212.33.camel-oEAf6al8vHAJnb1pzfbhCAUO+ZQNKbZIQQ4Iyu8u01E@public.gmane.org" type="cite"> <pre wrap="">On Wed, 2008-03-26 at 14:43 +0100, Mark Bush wrote: </pre> <blockquote type="cite"> <pre wrap="">Craig White wrote: </pre> <blockquote type="cite"> <pre wrap="">I seem to have @facilities = Facility.find(:all) in a lot of places in my application and my facilities model data rarely changes. How can I cache it so that I don''t have to hit the DB each time? </pre> </blockquote> <pre wrap="">class Facility < ActiveRecord::Base after_save {@@all_facilities = nil} def self.all_facilities @@all_facilities ||= self.find(:all) end end @facilities = Facility.all_facilities </pre> </blockquote> <pre wrap=""><!---->---- thanks - made it simple...I likee Craig </pre> </blockquote> Note this will only work if you are only running a single process.<br> <br> <pre class="moz-signature" cols="72">-- Jack Christensen <a class="moz-txt-link-abbreviated" href="mailto:jackc-/SOt/BrQZzMOf2zXYvRtkodd74u8MsAO@public.gmane.org">jackc-/SOt/BrQZzMOf2zXYvRtkodd74u8MsAO@public.gmane.org</a></pre> <br> --~--~---------~--~----~------------~-------~--~----~<br> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. <br> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en <br> -~----------~----~----~----~------~----~------~--~---<br> </body> </html> <br>
On Wed, 2008-03-26 at 09:17 -0500, Jack Christensen wrote:> Craig White wrote: > > On Wed, 2008-03-26 at 14:43 +0100, Mark Bush wrote: > > > > > Craig White wrote: > > > > > > > I seem to have @facilities = Facility.find(:all) in a lot of places in > > > > my application and my facilities model data rarely changes. How can I > > > > cache it so that I don''t have to hit the DB each time? > > > > > > > class Facility < ActiveRecord::Base > > > after_save {@@all_facilities = nil} > > > def self.all_facilities > > > @@all_facilities ||= self.find(:all) > > > end > > > end > > > > > > > > > @facilities = Facility.all_facilities > > > > > ---- > > thanks - made it simple...I likee > > > > Craig > > > > > Note this will only work if you are only running a single process.---- ruh-roh... I run several mongrels...no workee? Or will each cache separately? Craig --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> <title></title> </head> <body bgcolor="#ffffff" text="#000000"> Craig White wrote: <blockquote cite="mid:1206543073.25212.37.camel-oEAf6al8vHAJnb1pzfbhCAUO+ZQNKbZIQQ4Iyu8u01E@public.gmane.org" type="cite"> <pre wrap="">On Wed, 2008-03-26 at 09:17 -0500, Jack Christensen wrote: </pre> <blockquote type="cite"> <pre wrap="">Craig White wrote: </pre> <blockquote type="cite"> <pre wrap="">On Wed, 2008-03-26 at 14:43 +0100, Mark Bush wrote: </pre> <blockquote type="cite"> <pre wrap="">Craig White wrote: </pre> <blockquote type="cite"> <pre wrap="">I seem to have @facilities = Facility.find(:all) in a lot of places in my application and my facilities model data rarely changes. How can I cache it so that I don''t have to hit the DB each time? </pre> </blockquote> <pre wrap="">class Facility < ActiveRecord::Base after_save {@@all_facilities = nil} def self.all_facilities @@all_facilities ||= self.find(:all) end end @facilities = Facility.all_facilities </pre> </blockquote> <pre wrap="">---- thanks - made it simple...I likee Craig </pre> </blockquote> <pre wrap="">Note this will only work if you are only running a single process. </pre> </blockquote> <pre wrap=""><!---->---- ruh-roh... I run several mongrels...no workee? Or will each cache separately? </pre> </blockquote> Each process will have its own cache.<br> <blockquote cite="mid:1206543073.25212.37.camel-oEAf6al8vHAJnb1pzfbhCAUO+ZQNKbZIQQ4Iyu8u01E@public.gmane.org" type="cite"> <pre wrap=""> Craig </pre> </blockquote> <br> <br> <pre class="moz-signature" cols="72">-- Jack Christensen <a class="moz-txt-link-abbreviated" href="mailto:jackc-/SOt/BrQZzMOf2zXYvRtkodd74u8MsAO@public.gmane.org">jackc-/SOt/BrQZzMOf2zXYvRtkodd74u8MsAO@public.gmane.org</a></pre> <br> --~--~---------~--~----~------------~-------~--~----~<br> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. <br> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en <br> -~----------~----~----~----~------~----~------~--~---<br> </body> </html> <br>
Craig White wrote:> I run several mongrels...no workee? Or will each cache separately?Each will cache separately but what Jack means is that if one process makes a change, the others will not notice and they will have stale data. In that situation, you can cache in an external repository (such as memcache) which each thread is able to update. -- 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 -~----------~----~----~----~------~----~------~--~---
On Wed, 2008-03-26 at 16:38 +0100, Mark Bush wrote:> Craig White wrote: > > I run several mongrels...no workee? Or will each cache separately? > > Each will cache separately but what Jack means is that if one process > makes a change, the others will not notice and they will have stale > data. > > In that situation, you can cache in an external repository (such as > memcache) which each thread is able to update.---- cool...I''m install memcached now (Linux) and simulataneously making sure that it''s available for my production system. That seems to be a better way to go Thanks Craig --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---