[Zope3-dev] Re: rdb: Disappearing Connection
Tres Seaver
tseaver at palladion.com
Tue Dec 13 20:40:37 EST 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Florent Guillaume wrote:
> Jim Washington wrote:
>
>> Spelunking a bit in the code,
>> zope.app.rdb.ZopeDatabaseAdapter.isConnected() looks at whether
>> _v_connection is present, not whether the connection is actually
>> alive. If we fix this here, isConnected() perhaps should handle the
>> case where the connection might be reaped by the back end db.
>
>
> Frankly anything that uses _v_ attributes is asking for trouble because
> it relies on low level behaviour of the ZODB and persistence mechanisms.
> They can disappear at unpredictable times. Avoid them.
There *is* a reasonable pattern for using them, with the following
caveat: the value you are caching must depend *only* on other
attribtues of the *same* persistent object *or* its non-persistent
subobjects (i.e., the values are pickled / ghostified as part of the
same ZODB record).
In this case, the following works entirely as expected:
class Foo(SomePersistentBaseClass):
_v_cache_an_expensive_operation = None
def getExpensiveResult(self):
if self._v_cache_an_expensive_operation is None:
self._v_cache_an_expensive_operation = _expensive()
return self._v_cache_an_expensive_operation
This pattern is reliable because the volatile will be wiped if *any* of
the attributes of its object are modified, at the point that the
transaction (or subtransaction) commits / reaches a savepoint.
If '_expensive' depends on *any other persistent object*, you lose
(eventually, anyway).
Tres.
- --
===================================================================
Tres Seaver +1 202-558-7113 tseaver at palladion.com
Palladion Software "Excellence by Design" http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFDn3gV+gerLs4ltQ4RAmekAKCf8ByFHX9beo51HUYOYyIoAm6eswCfRkLi
czMxyJZPhaKMgq6K1lJup6g=
=gkrJ
-----END PGP SIGNATURE-----
More information about the Zope3-dev
mailing list