[Zope-dev] Re: Z SQL Caching

Martijn Pieters mj at zopatista.com
Mon Sep 26 14:49:04 EDT 2005


Dale Hirt wrote:
> I have a Z SQL method that is currently returning around 25000 rows. 
> Is there a way to see if it is pulling that data from the cache or is
> doing a refresh?
> 
> Alternatively, and maybe this will answer the first question, the Z SQL
> method is run essentially twice, each time with different parameters. 
> Does it cache each instance, or does it cache the first, then when it's
> run again with different parameters, kill the cache and re-run
> everything?

A ZSQLMethod cache (if configured with a cache duration greater than 0) 
is keyed on the rendered SQL. So, if different parameters lead to a
different SQL query to be sent to the database, then a different key is
used. Caches are kept for the duration of the configured cache duration,
and a given cache key will not influence earlier caches of different
keys.

The SQL is taken quite literally here. If you use the following template: 

  SELECT * FROM foo WHERE <dtml-sqltest bar type="nb">

Then different values for 'bar' will result in different SQL queries and
thus different cache keys. If the same method is called with the same
value for 'bar' within the cache duration, an earlier cached result will
be returned instead of querying the database. Another value for 'bar' in
between those calls will not kill the cache.

Martijn Pieters




More information about the Zope-Dev mailing list