[Zope-DB] Controlling Z SQL caching

Dieter Maurer dieter at handshake.de
Thu Feb 26 15:37:07 EST 2004


Ian Bicking wrote at 2004-2-25 16:42 -0600:
> ...
>Our administrator is a little wary of SharedResource -- I think he's 
>worried it may not be portable across versions of Zope, or something of 
>that sort.  From my (very brief) look, it seems like it's really very 
>Zope neutral (maybe too neutral, hence not working with ZEO), and 
>shouldn't be a problem when upgrading Zope.  Any warnings or 
>reassurances you might be able to provide?

"SharedResource" is completely independant of Zope.
You see this at the fact that it does not import any
Zope module.

>When you say it won't work with ZEO, I assume that means that cache 
>purges won't be propagated to different Zope instances, since 
>SharedResource (and hence caching) is not ZODB-aware (which would 
>otherwise be fine for a cache).

The resources live in RAM and RAM is not shared among ZEO clients.

>> I don't see any way to do that with Z SQL methods. 
>> 
>> You can flush the cache by writing the Z SQL Method ("_p_changed=1")
>> and deleting its "_v_" attributes.
>
>Hmm, like (?):
>
>def purgeCache(zSQLMethod):
>     zSQLMethod._p_changed = 1
>     # Maybe some ZODB stuff I don't understand (I'm a ZODB-newbie),
>     # my vague guess:
>     get_transaction().commit()
>     del zSQLMethod._v_cache

You should not do the commit here.

You should take care that "_v_cache" might not be defined
(e.g. use "try: ... except:" or first check whether it is
defined and only then delete it.

I do not know whether the cache is maintained in "_v_cache".

>Or do I have the _v_cache and _p_changed backwards?  I guess I don't 
>really understand this.

It does not matter.

The "_p_changed=1" takes effect on commit.
It writes the state of the Z SQL Method to ZODB.
This sends invalidation messages to all other ZODB connections.
They flush the Z SQL Method from the (ZODB) cache and
thereby effectively destroy whatever was held in "_v_" attributes.

>(BTW, I had a problem with CCSQLMethods/SQL.py, line 51:
>     manage_main=HTMLFile('../ZSQLMethods/edit', globals())
>Changed to:
>     manage_main=HTMLFile('../ZSQLMethods/dtml/edit', globals())
>and it works fine)

Thank you for the report.

-- 
Dieter



More information about the Zope-DB mailing list