[Zope] Semi-persistent objects, volatile attributes
Alexander Staubo
alex@mop.no
Fri, 27 Aug 1999 09:47:15 +0200
Is it possible to have persistent objects with attributes that are only
persistent in memory? Effectively, an object that is always cached, for
volatile attributes to be preserved during the Zope process' execution.
Is there a way for an object to load itself permanently into the cache,
say?
I figure I could store the attributes in the product module as part of a
dictionary keyed by the object instance, but this feels very dirty.
Speaking of volatile attributes, is there an idiom for handling these?
Since they're not stored, and __init__() is only ever called when the
object is initially created (not persistently loaded), it seems you have
to verify their existence, something like:
def my_method(self):
self._v_foo = (hasattr(self, '_v_foo') and self._v_foo) or
'<default>'
...ad tedium if you have lots of methods. Does the persistence engine
support an "onload" mechanism which you can override to know when your
instance has been loaded and needs to initialize itself?
Pointers to appropriate documentation would be nice. I've been rummaging
through the ZODB UML stuff and while it's enlightening, the
documentation is also quite fragmented.
--
Alexander Staubo http://www.mop.no/~alex/
"Give me an underground laboratory, half a dozen atom smashers and a
beautiful girl in a diaphanous veil waiting to be turned into a
chimpanzee, and I care not who writes the nation's laws."
--S. J. Perelman