[Zope] How to keep an object in the zodb cache?

Dieter Maurer dieter@handshake.de
Fri, 25 Jan 2002 22:43:50 +0100


Gregory Popovitch writes:
 > I am writing a product which loads a large python structure
 > object from disk. I don't wish to store this structure in the Zope
 > Zodb, so I load it in a variable prefixed with _v_.
 > 
 > The code looks like:
 > 
 > class myproduct(SimpleItem.SimpleItem):
 > 
 >     def __init__(self, id, title):
 >         " initializes a new instance of a myproduct"
 >         self.id = id
 >         self.title = title
 >         self._v_store = None
 > 
 >     def load(self):
 >         " load store into memory "
 >         import mystore
 >         if not hasattr(self, '_v_store') or not self._v_store:
 >              print "loading store"
 >              self._v_store = mystore.LoadStore(self.title)
 > 
 > The function self.load() is called from each URL method to ensure
 > that the store is loaded.
 > 
 > My problem is that after some inactivity in the web server, I can see
 > that the store is reloaded when a web page is requested, and it takes
 > some time.
 > 
 > I assume that the object self._v_store has been flushed from the zodb cache
 > and discarded.
Your "self" is flushed from the cache, when it is later reloaded
from ZODB, it lost its "_v_store".

I do not know a way how to prevent selective objects from being
flushed. But you can globally change flushing behaviour in
"Control Panel"->"Database Management"->"Cache Management" (or some
similar path).


Dieter