Eric S. wrote:
I have an app - a first cut ROR - so it’s a bit of a mess. I’m now
trying to clean it up. The app relies on a heap of look-up tables that
are, by and large, static. I’m wondering where and how to initialise
these collections once - so that I don’t have to keep hitting the
database every time I start a new action.
Can I initialise the collections at the start of a session - say in the
application controller - and have them persist for the whole session?
If the lookup tables are application-wide (ie, they don’t rely on userA
being logged in with a
session) you can stored them in a class variable on your controller.
During the dispatch.fcgi
process existance they will exist. For each new dispatch.fcgi process
that starts up, it will
require to load the lookup table information. This is probably your
You don’t want to store them in an instance variable on the controller
though because for each new
request you will be getting new instances of your controllers.
If you have alot of data in your lookup tables and you don’t want to
have to keep the same data
around for every dispatch.fcgi process running you can you could create
a UNIXSocket server where
you house the data, and have your controller’s communicate to that via
UNIXSocket Although this may
be overkill. =) For cross-platform compatibility you could use a TCP
Server, and connect via a
TCPSocket, but that up to you!