[ZODB-Dev] [Problem] "_v_" variables too volatile

Shane Hathaway shane at zope.com
Thu Dec 11 14:08:51 EST 2003


On Thu, 11 Dec 2003, kapil thangavelu wrote:

> the only alternative I've found acceptable is to convert uses of _v_ to a
> system of module level global variables for use as thread specific storages
> with application linking (I normally cheat and use _p_oid) to items in the
> storages. for legacy code _v_* get converted to computed attributes with
> accessors that do lookup and creation, it works.. but ick.

At a high level, this problem could be solved nicely using descriptors.

class Foo(Persistent):

    # _cache attributes may revert to the default on transaction
    # and subtransaction boundaries.
    _cache = Volatile("_cache", default=None)

    # _trans_cache attributes revert to the default on transaction 
    # boundaries.
    _trans_cache = Sticky("_trans_cache", default=None)

    def getSomething(self):
        if self._cache is None:
            self._cache = compute_something_expensive()
        return self._cache

The Volatile and Sticky classes have __get__ and __set__ methods that 
interact with ZODB in whatever manner is appropriate.

Shane



More information about the ZODB-Dev mailing list