I need to load some read-only lookup data from the database into memory for fast access (i.e. caching). What''s the best way to cache data in memory in Rails apps? For example, should I use global, class or instance variables? I realize each controller in my cluster will have it''s own copy, which is fine. Thanks in advance. -- 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 6 Nov 2008, at 23:28, Ben Knight wrote:> > I need to load some read-only lookup data from the database into > memory > for fast access (i.e. caching). What''s the best way to cache data in > memory in Rails apps? For example, should I use global, class or > instance variables? I realize each controller in my cluster will have > it''s own copy, which is fine. >Doesn''t need to be anything cleverer than a class variable (or a class instance variable). Fred> Thanks in advance. > -- > 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 -~----------~----~----~----~------~----~------~--~---
Thanks, Fred. Has anyone used Rails.cache.write / read? I wonder how good of a solution that is. -- 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 7 Nov 2008, at 15:00, Ben Knight wrote:> > Thanks, Fred. > > Has anyone used Rails.cache.write / read? I wonder how good of a > solution that is. >I haven''t used it, but it is a different beast. It is something that is shared across all the processes in your cluster, so it''s doing more which implies that it will have more overhead then just reading an instance variable out of something. It also uses Marshal.dump to dump the objects it stores which can introduces some complexities) Fred> -- > 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 -~----------~----~----~----~------~----~------~--~---
PS. I''m wondering if Rails.cache is better or Memcache. Thanks again. -- 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 7 Nov 2008, at 15:09, Ben Knight wrote:> > PS. I''m wondering if Rails.cache is better or Memcache. Thanks again.That''s sort of a non question - Rails.cache can be backed by several different stores, one of which is memcache. Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks again! Frederick Cheung wrote:> On 7 Nov 2008, at 15:09, Ben Knight wrote: > >> >> PS. I''m wondering if Rails.cache is better or Memcache. Thanks again. > > That''s sort of a non question - Rails.cache can be backed by several > different stores, one of which is memcache. > > Fred-- 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 -~----------~----~----~----~------~----~------~--~---
Exactly Fred. Ben, I have had experience using Rails.cache as memcache as the store. And it''s worked a treat. #in environment.rb config.cache_store = :mem_cache_store, {:namespace => "your_app"} It would be best to use the rails built in method because if something comes along like a newer or alternative method of caching you only have to modify a few bits of your code or even none at all. Just update your Rails or gems or whatever. Your caching code doesn''t require any modification. Regards, Andrew On Nov 7, 4:46 pm, Ben Knight <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Thanks again! > > Frederick Cheung wrote: > > On 7 Nov 2008, at 15:09, Ben Knight wrote: > > >> PS. I''m wondering if Rails.cache is better or Memcache. Thanks again. > > > That''s sort of a non question - Rails.cache can be backed by several > > different stores, one of which is memcache. > > > Fred > > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks a bunch; I''ll use Rails.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 -~----------~----~----~----~------~----~------~--~---