Are there any downsides to doing something like this assuming Foo data
rarely changes?
class Foo < ActiveRecord::Base
  class << self
    def get_all_foo
      @foo || Foo.find(:all)
    end
  end
end
Is it ok to cache this data so you don''t constantly reload it from the
database.  How long does @foo last?  Just for the length of one request
or until the server is restarted?
Thanks,
Aaron
--~--~---------~--~----~------------~-------~--~----~
 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
-~----------~----~----~----~------~----~------~--~---
Are there any downsides to doing something like this assuming Foo data
rarely changes?
class Foo < ActiveRecord::Base
   class << self
     def get_all_foo
       @foo || Foo.find(:all)
     end
   end
end
Is it ok to cache this data so you don''t constantly reload it from the
database? How long does @foo last?  Just for the length of one request
or until the server is restarted?
Thanks,
Aaron
(sorry if this message is a dupe, I tried posting through the google  
interface first)
--~--~---------~--~----~------------~-------~--~----~
 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 12/20/06, Aaron Baldwin <baldwina-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Are there any downsides to doing something like this assuming Foo data > rarely changes? > > class Foo < ActiveRecord::Base > class << self > def get_all_foo > @foo || Foo.find(:all) > end > end > end > > Is it ok to cache this data so you don''t constantly reload it from the > database? How long does @foo last? Just for the length of one request > or until the server is restarted?I believe that this will only last for the duration of a request. If you want it to be persistant, you could put it into the environment.rb file and it would persist over many calls. Probably a better way to do this is to use memcache though. There are a number of good plugins that allow you to use this. A nice one by Chris Wanstrath <http://www.agilewebdevelopment.com/plugins/owner/166> can be found at http://www.agilewebdevelopment.com/plugins/acts_as_cached Hope that helps --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---