Toby Dickenson wrote:
Ok, from your exlanations, MemberDataTool should be now safe -- I patched it a few weeks ago to clear the cache at the end of the transaction using REQUEST._hold.
BTW, I use the attatched class to delete an attribute from an object at the end of a transaction. This is a little safer than REQUEST._hold in cases where request boundares are not aligned with transactions. Should this go in ZODB somewhere?
It would be nice, yes. It would provide a better abstraction that REQUEST._hold and if you say it's safer, then that's a win too. Regarding Steve's suggestion:
I'd like to see attributes that get cleared at transaction boundaries made a first-class feature of the ZODB. This might be implemented for attributes starting with _x_ where x is The letter of your choice, following a similar pattern to _v_ and _p_ attributes.
It would be also very useful. _v_ is volatile, but not volatile enough... :) Florent
------------------------------------------------------------------------
""" attribute_cleaner
A class to remove an attribute from an object at the end of a transaction. This is useful for attributes that hold transaction-specific caches.
Normal operation is::
if self._v_cache is None: self._v_cache = create_data_to_cache() attribute_cleaner(self,'_v_cache') """
class attribute_cleaner: def __init__(self,client,attr): self.client = client self.attr = attr get_transaction().register(self)
def sortKey(self): return repr(self)
def ClearCache(self,*args): try: delattr(self.client, self.attr) except AttributeError: pass except KeyError: pass
tpc_finish = tpc_abort = abort = abort_sub = ClearCache
def tpc_begin(self,transaction,subtransaction=None): pass def commit(self,object,transaction): pass def tpc_vote(self,transaction): pass def commit_sub(self,transaction): pass
-- Florent Guillaume, Nuxeo (Paris, France) +33 1 40 33 79 87 http://nuxeo.com mailto:fg@nuxeo.com