-----BEGIN PGP SIGNED MESSAGE-----
Dieter Maurer wrote:
> Tres Seaver wrote at 2008-9-17 15:06 -0400:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>> Dieter Maurer wrote:
>>> Tres Seaver wrote at 2008-9-12 06:35 -0400:
>>>> Reimplementing Pickle Cache in Python
>>>> from zope.interface import Attribute
>>>> from zope.interface import Interface
>>>> class IPickleCache(Interface):
>>>> """ API of the cache for a ZODB connection.
>>> Which method moves an object to the front of the ring?
>>> Or do you use an inline expansion for speed reasons?
>> Thanks for catching my error. In the current implementation, the C
>> version of the Persistent base class calls a static C helper function
>> inside its 'accessed' method, which is called from the various attribute
>> getter and setters.
>> My implementation of the ring in Python needs to grow another method
>> which takes the place of that helper. Something like:
>> class IPickleCache(Interface):
>> def mru(oid):
>> """ Move the element corresonding to 'oid' to the head.
>> The implementation would look something like:
>> class PickleCache(object):
>> def mru(self, oid):
>> node = self.ring.next
>> while node is not self.ring and node.object._p_oid != oid:
>> node = node.next
> The "while" worries me a bit: "mru" is called for any attribute access
> and must therefore strive for efficiency.
I think we could relax the "any attribute access" bit and still win (in
fact, that seems absurd on the face of it). I don't know what the
secret would be: maybe we have to track an "mtime" of some kind, and
bump the 'mru()' method only when the mtime changes (no more than once
per transaction, even for reads, seems sane). In fact, one could argue
that attribute access is exactly *wrong*: the right time to hit move
the item to the head of the list is when the object is fetched from the
> Another problem is thread safety.
> The C implementation could rely on the GIL being held.
> I fear that a Python implementation would need to use explicit locking.
That might be problematic for the general case, although we never share
a connection across threads in Zope.
Tres Seaver +1 540-429-0999 [EMAIL PROTECTED]
Palladion Software "Excellence by Design" http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
-----END PGP SIGNATURE-----
For more information about ZODB, see the ZODB Wiki:
ZODB-Dev mailing list - ZODB-Dev@zope.org