[Zope] SharedResource insight ?

Dieter Maurer dieter at handshake.de
Fri Jul 23 14:52:14 EDT 2004


Paolo Bizzarri wrote at 2004-7-23 16:48 +0200:
> ... transaction aware cache management ...
>We are looking for some product to provide a cache shared between all
>the threads in Zope, and I think we could use the SharedResource (see 
>http://www.dieter.handshake.de/pyprojects/zope/SharedResource.html) module 
>for such a purpose. This cache will mantain objects built from an SQL 
>database.
>
>However, we have some doubt regarding Zope transactions and cache
>management. 
> ...

Your doubts may be justified.

  "SharedResource" is not transaction aware.

  When a transaction puts something into the resource and
  later aborts, it is is still in the "SharedResource".

  Moreover, other transactions can see it before the changing
  transaction commits.

For many applications, this is not very problematic -- e.g.
when you cache the result of SQL methods. Usually, such SQL methods
put only committed changes into the cache (however, it is
easy to construct application for which even this is not true).

When you really need transaction awareness, it is probably best
to put your cache into a mounted ZODB backed by e.g. a RAM storage --
very similar to how Zope manages sessions nowadays.
You can even use Zope's "temp_folder" for this purpose (put an
appropriate BTree based (!) cache manacher into this folder).

-- 
Dieter


More information about the Zope mailing list