Greg H. wrote:
Class variables in a model are ok to cache relatively static records
within the scope of a brower call aren’t they? That is, the results get
“refreshed” effectively each browser call (i.e. per browser call, per
mongrel process). Example of what I’m talking about is below.
@@all_records = nil
@@all_records ||= Automatch.find(:all) # say only 10 records,
Technically yes, and esthetically no.
You are “coupling” the state of your model to its current location in
flow. If control flow changes, your coupling might break. If, for
added a new feature that required two model objects, extant at the same
then their @@all_records might accidentally conflict. Decoupled code is
to safely change - that’s essentially the definition of “decoupled”.
Take out @@all_records = nil entirely, then use @all_records =
Automatch.find(:all). If your controller and similar code is also
won’t create more instances of your model than it needs, and they will