Forum: Ruby on Rails Caching data to reduce database hits

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Aaron (Guest)
on 2006-12-31 01: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)

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?

This topic is locked and can not be replied to.