Cache-Block-Usage?

Author Message

Marco Zinn

Tuesday 02 December 2003 8:52:53 am

Hi,
i'm missing some good and precise documentation about the usage of cache-blocks in the pagelayout template.

I know, that the general usage should be somehow like:
{cache-block}
... menues / navigation
{/cache-block}
{$module_result.content}
{cache-block}
... footer / navigation
{/cache-block}

Also, you can add keys to determine the different "versions" of a given cache-block.
But how is this all used? What happens with a cache-block without keys? Which keys are used then? Is there any human-understandable system, which determines the cache-blocks filenames in the filesystem?

Marco
http://www.hyperroad-design.com

Paul Borgermans

Tuesday 02 December 2003 9:43:44 am

Hi Marco,

Whether or not you provide keys, the template cache system will create additional ones based on the template file name and path, the position of the cache-block in the file and the current siteaccess. So multiple cache-blocks in a template file with no explicit keys still get a unique key. This works even if different siteaccess use the same design (and templates within). The latter is necessary because the content may differ with siteaccess.

The use of keys is mandatory when you use the cache-block in a template and the content of the cache-block can be different. For view templates, I would recommend at least the node_id +the userid (if different users have different roles). You may add other variableshere too.

For use in pagelayouts and you have navigation menus which remain constant, it is safe to use no keys at all for the surrounding cache-block. Otherwise, you will need a key which discrimnates the different content (eg the user id when roles affect the menus to display).

hth

-paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Ben Pirt

Wednesday 03 December 2003 5:31:57 am

Hi Marco,
It's very true that good documentation is lacking on the use of cache-block. I have just been investigating it and here is what I found (please correct me, anyone if this is wrong, it would be useful for both me and others)

The cache-block directive caches that block of code and everywhere it is used in a template, the faster, cached version is used. This is all well and good if you have content which doesn't change, but gets more complicated when it does. So, in the case of a menu;

If you have the same menu on every page, then you can just use cache-block without setting a keys variable and it should work fine.

If you have a 2 level nested menu like;

contact
projects
---- project 1
---- project 2
other

and the second level depend which node you are looking at, you need to use the keys variable to cache a different chunk of code for each instance of this. So, in this case, if you were using $module_result.node_id to determine which sub menu to expand, you would do the following;

{cache-block keys=$module_result.node_id}
{code goes here}
{/cache-block}

which will cache a different version of this block for every node.

Going one step further (which I haven't yet, but still) if you have a section of code which is dependent upon two variables for it's output, you use both of these as the key, e.g. if it is dependent upon $module_result.node_id and $user (or whatever the variable which has the current user - I can't recall). You would do;

{cache-block keys=array($module_result.node_id, $user)}
{code goes here}
{/cache-block}

I have just implemented cache-block on my site and it speeded up server response times considerably. Well worth doing. Anyway, hope this helps (and was correct)

All the best,
Ben Pirt

Bård Farstad

Thursday 04 December 2003 2:51:54 am

I've added a new documentation page which should explain this a bit more:
http://ez.no/developer/ez_publish_3/documentation/incoming/cache_block_optimization

Documentation: http://ez.no/doc

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 22:28:35
Script start
Timing: Jan 18 2025 22:28:35
Module start 'layout'
Timing: Jan 18 2025 22:28:35
Module start 'content'
Timing: Jan 18 2025 22:28:36
Module end 'content'
Timing: Jan 18 2025 22:28:36
Script end

Main resources:

Total runtime0.7948 sec
Peak memory usage4,096.0000 KB
Database Queries64

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0093 589.2266152.6094
Module start 'layout' 0.00930.0045 741.835939.4297
Module start 'content' 0.01380.7793 781.2656645.1328
Module end 'content' 0.79320.0016 1,426.398416.1875
Script end 0.7947  1,442.5859 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00320.4070160.0002
Check MTime0.00130.1627160.0001
Mysql Total
Database connection0.00160.200310.0016
Mysqli_queries0.719890.5661640.0112
Looping result0.00080.0972620.0000
Template Total0.751594.620.3757
Template load0.00210.261120.0010
Template processing0.749494.289420.3747
Template load and register function0.00030.035610.0003
states
state_id_array0.00170.217210.0017
state_identifier_array0.00150.192520.0008
Override
Cache load0.00180.2210510.0000
Sytem overhead
Fetch class attribute can translate value0.00100.127740.0003
Fetch class attribute name0.00130.161370.0002
XML
Image XML parsing0.00170.219540.0004
class_abstraction
Instantiating content class attribute0.00000.001770.0000
General
dbfile0.00370.4717300.0001
String conversion0.00000.001040.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
9content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
10content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 28
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs