Caching data to reduce database hits


#1

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