On Tue, 2002-11-26 at 11:52, Wayne Larsen wrote:
> As a related question, do you
> know how MiddleKit manages caching?
MiddleKit keeps a cache (essentially a dictionary) of references to each
objects which it has loaded. Also, any object which has a "List of"
attribute will cache the list of objects, so it doesn't have to query
the database each time.
> I wonder if MiddleKit has a mechanism to discard objects in memory?
ObjectStore has a clear() method which can be called if there are no
outstanding changes; it causes the store to clear its cache. All
subsequent fetch*() calls will instantiate fresh objects. Be careful
not to shoot yourself in the foot, though: if you have a reference to a
middle object, then call store.clear(), and change the objects's
attributes without re-fetching it from the store, you will probably end
up with undefined results. :)
> I would be interested in seeing your solution. It
> seems like a good compromise, since it would apply to
> all MiddleKit objects.
Ok, here goes:
1. If you're not using Webware from CVS, you need to apply the attach patch
to your Webware/WebKit directory, which fixes a couple of oversights in the
SessionStore.py and SessionDynamicStore.py files. These fixes make it possible
to set our own encoder/decoder for sessions. If you're using CVS, just do an
update, since I checked in these fixes this afternoon.
2. Stick the attached MiddlePickle.py file somewhere in your PYTHONPATH.
3. Now you just need to arrange for this custom encoder/decoder to be used.
I override Application and do it there, but you'll probably want to do it in
your contextInitialize() method, or whereever you instantiate your global store.
Assuming that 'store' is your global store instance, and 'app' is the
application instance, the code looks something like this: