-----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
           if node is self.ring:
               raise KeyError('Unknown oid: %s' % oid)
           # remove from old location
           node.prev.next, node.next.pref = node.next, node.prev
           # splice into new
           self.ring.prev, node.next = node, self.ring

That method would then be called by the corresponding 'acceseed' (or is
it '_p_accessed'?) method in the new Persistent class.


Tres.
- --
===================================================================
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

iD8DBQFI0VU/+gerLs4ltQ4RAtb6AJ98MBvPQ+4DTDs6TDYNfaXPhLVJZwCfd6bd
prN6YvDRBhc1lbwwfFnsR/g=
=UOSG
-----END PGP SIGNATURE-----

_______________________________________________
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zodb-dev

Reply via email to