Caching and variables.

Author Message

martin k

Thursday 16 March 2006 8:26:55 am

Hi,

I want to enable cache to speed up site access. I'm quite a newbie whent it comes to enabling caching, but this is what I've done in override/site.ini.append.php:

[TemplateSettings]
TemplateCache=enabled
TemplateCompile=enabled
TemplateCompression=enabled
TemplateOptimization=enabled

[RegionalSettings]
TranslationCache=enabled

[ContentSettings]
ViewCaching=enabled
PreViewCache=disabled

Now I have some problems with accessing variables like $node.node_id, etc. When I enable caching with cache blocks, I get all kind of weird problems like images not being updated in a gallery before the cache expires. I read a forum post about using $module_result.content instead, but it's only available in pagelayout.tpl? I couldn't access this variable in any of my override templates.

Anyway, here is an example of a override template where I'm using a cache block.

{* beginning of template *}

{set-block scope=root variable=cache_ttl}0{/set-block}

{cache-block expiry=20 keys=$uri_string}
{* some code for a image gallery *}
{foreach $galleries as $m}
        {if or(eq($m.node_id, $node.node_id), eq($node.parent_node_id, $m.node_id))}
                <p class="redcolor"><a class="redcolor" href={$m.url_alias|ezurl}>{$m.name|wash|upcase}</a></p>
        {else}
                <p><a href={$m.url_alias|ezurl}>{$m.name|wash|upcase}</a></p>
        {/if}
{/foreach}


{/cache-block}

Now the big question here is if I'm doing this the right way. I've had a hard time gathering some scattered information about how to implement cache in eZ. I guess I just can't use cache-blocks everywhere, and have to test and try if it works in different settings?

Betsy Gamrat

Thursday 16 March 2006 9:08:05 am

The key is in the <b>keys</b>.

I like to use the node id in the keys to ensure the content is properly cached.

For example:

keys=array("details",$node.node_id)

I disable ViewCaching and rely on the template caching.

I've never tried to preserve variable values between template accesses.

There are also additional static caching features in eZ.

If you need to support a very high level of traffic, you can do several things:

Preprocess the home page (demo at http://wirehopper.com/php/preprocess.php, article in Dr. Dobb's Journal Jan 2006)

Modify pagelayout.tpl to support a very streamlined delivery of content and extract it using a cron job.

Use the CMS to build PHP. That way, the content is still dynamic, but it is lightning fast.

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 19:19:01
Script start
Timing: Jan 18 2025 19:19:01
Module start 'layout'
Timing: Jan 18 2025 19:19:01
Module start 'content'
Timing: Jan 18 2025 19:19:02
Module end 'content'
Timing: Jan 18 2025 19:19:02
Script end

Main resources:

Total runtime0.8672 sec
Peak memory usage4,096.0000 KB
Database Queries54

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0077 587.9063152.6250
Module start 'layout' 0.00770.0041 740.531339.4453
Module start 'content' 0.01180.8540 779.9766499.4297
Module end 'content' 0.86580.0014 1,279.406312.1719
Script end 0.8672  1,291.5781 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00320.3704160.0002
Check MTime0.00140.1593160.0001
Mysql Total
Database connection0.00080.092910.0008
Mysqli_queries0.816194.1085540.0151
Looping result0.00060.0740520.0000
Template Total0.826995.420.4134
Template load0.00220.252320.0011
Template processing0.824795.098920.4123
Template load and register function0.00020.018710.0002
states
state_id_array0.00130.146910.0013
state_identifier_array0.00170.201620.0009
Override
Cache load0.00170.1940320.0001
Sytem overhead
Fetch class attribute can translate value0.00060.069120.0003
Fetch class attribute name0.00120.133330.0004
XML
Image XML parsing0.00070.079820.0003
class_abstraction
Instantiating content class attribute0.00000.000930.0000
General
dbfile0.00090.1053160.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
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
6content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 15
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs