Re: preloading/caching small tables

Steve Downey
2005-07-28T18:16:07Z

Imran Patel <imran.patel@...> writes:

>
> Hi,
>
> I have couple of small database tables that I would like to get
> pre-loaded (as hash[id] = value) "once" in my app at startup. I
would
> like to access the resulting hashes in my Controller logic. I have
> tried looking for answers on the wiki but haven''t been very
> successful. What would be the best way to do this?
>
> Thanks
> imran


Don''t know if RoR has the equivalent of an Application object, but how
about
something in each model like:

@@all_rows = self.find(:all)

def all_rows
  @@all_rows
end

Then you could reference Model.all_rows and only take the hit to the database
once.