On Oct 26, 2007, at 7:41 AM, Gernot K. wrote:
your
app state lives in the server. Don’t confuse caching with app state.
Try to design your app stateless, that’s what I learned from Rails.
And
it works beautifully.
This isn’t data that belongs in a session.
I use globals as a mini memcache (at least I did with Lasso, and now
I’m assuming I can recreate that with Ruby). It’s a hash of data
being stored in partially processed formats.
In my case I’ll have a particular global dedicated to caching a
particular type of data. The global will be created by the system
that needs it, when it needs it. This way I can build sub-systems
that create their own environment needs. If I need a db mapper, I
install that. It creates it’s own global for caching the various
cross reference structures created from mapping definitions.
Example: I load value list definitions from a text file (or db, or
even web service, source doesn’t matter). Many value lists are stored
in one file, or retrieved with one query. These definitions do not
change, they’re part of fixed options in the application design. I
lazy load the lists as they’re needed, parse each list into a data
structure suitable for passing as options to a renderer, then cache
each parsed list.
I have my own value list renderer class that provides some options
and application-integration capabilities different than the Rails
one. Some lists require on the fly additions or subtractions at
various points in the application (modular app hierarchy, or
permissions based adjustments). I can pull the base list from the
cache and modify it in the controller before passing a var with the
final list to the renderer in the view.
Also, I might go ahead and store a baseline HTML rendering of a value
list in the cache, and then use regex to alter its final state. This
is usually the fastest way to generate valuelists. On pages with a
handful of them it doesn’t matter so much. On pages with many of them
or, several long ones, it can make a difference.
I know Rails has some tools for this, but IMO they’re more cumbersome
than my system, and they simply don’t allow for some of the
flexibility I need.
My using globals tends to be for application config/reference, so
while using globals is good for creating machine-specific caches, I
wouldn’t use it for data where it would make more sense to use
something like memcached.
– gw