Forum: Ruby on Rails Caching data to reduce database hits

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8da92d4ed91aa12535f6d870fa76b25e?d=identicon&s=25 Aaron (Guest)
on 2006-12-31 00:34
(Received via mailing list)
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
This topic is locked and can not be replied to.