[Zope-dev] _v_ and ZEO

Toby Dickenson tdickenson@geminidataloggers.com
Fri, 19 Apr 2002 10:43:01 +0100


On Thu, 18 Apr 2002 17:35:17 +0000 (UTC), Florent Guillaume
<fg@nuxeo.com> wrote:

>I'll investigate clearing the _v_ caches at the end of the transaction,
>using the REQUEST._hold hack mentionned earlier.

Below is the class I use for this. Just call
attribute_cleaner(self,'_v_my_attribute') before assigning to
_v_my_attribute, and it will be cleared at the end of the ZODB
transaction.

I wonder if this is generally useful enough to go in the ZODB
distribution?



class attribute_cleaner:
    def __init__(self,client,attr):
        self.client =3D client
        self.attr =3D attr
        get_transaction().register(self)

    def ClearCache(self,*args):
        try:
            delattr(self.client, self.attr)
        except AttributeError:
            pass
        except KeyError:
            pass

    tpc_finish =3D tpc_abort =3D abort =3D abort_sub =3D ClearCache

    def tpc_begin(self,transaction,subtransaction=3DNone): pass
    def commit(self,object,transaction): pass
    def tpc_vote(self,transaction):      pass
    def commit_sub(self,transaction):    pass




Toby Dickenson
tdickenson@geminidataloggers.com