node_view_gui and cache

Author Message

Atle Pedersen

Friday 10 July 2009 4:46:25 am

I have the following situation:

{foreach $nodelist as $n}
{node_view_gui content_node=$n view='complex_data''}
{/foreach}

What I would like the cache system to do here is to create and maintain a cache file for each node and the particular view. This way, when one of the nodes are changed, only the appropriate cache needs to be regenerated.

I've experimented a little bit, but it doesn't seem to work this way. I get a cache file for the main, but not anything for the custom view. So I have to recreate cache for the whole file, including all the other unchanged nodes.

Is there a mechanism for this eZ?

Gaetano Giunta

Friday 10 July 2009 5:08:57 am

Add a {cache-block} statement inside your foreach loop, using node_id as key.

Take care about your objects being modified, though: the cache block might not be expired automatically (read up the onlinde docs about cache blocks for more details)

Principal Consultant International Business
Member of the Community Project Board

Atle Pedersen

Friday 10 July 2009 6:05:52 am

Thank you, I forgot that cache-block can be used in all templates.

I ended up with something like this:

{cache-block keys=array($node.node_id,'loop1') subtree_expiry=$node.url}
  {def $nodelist=fetch(...)}
  {foreach $nodelist as $n}
    {cache-block keys=array($n.node_id,'loop1') subtree_expiry=$n.url}
      {node_view_gui content_node=$n}
    {/cache-block}
  {/foreach}
{/cache-block}

I have only tested it superficially, but it seems to work and give good speed increase compared to uncached version. I do need a {set-block scope=global variable=cache_ttl}0{/set-block} on top though. Probably because I need the list to be updated when children of children are being changed.

One short question, is using $node.url a good way to set subtree_expiry?

André R.

Friday 10 July 2009 7:15:36 am

That might work, but it kind of looks like a hack.
Next time you think about implementing stuff like this, use relations (object or attribute) or structure, then the Content View Cache system is able to clear the cache for you when content is edited meaning you don't need to use cache_ttl=0.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Gaetano Giunta

Friday 10 July 2009 8:36:56 am

Using $node.node_id should also work as subtree_expiry key.

The ttl=0 on top is there because otherwise the whole template will only be executed when the current node changes and its result stored in the view cache. It will thus not be updated anytime any of the included object or their subchildren change.

I fully agree with Andre that it looks ugly though: using object relations is the best way to get proper change propagation within eZ view caches.

Last but not least, the main question, that has been left unsaked: how comes the standard view cache is not enough for your needs?
I can imagine 2 reasons:
- the list of nodes included in the loop is huge
- the templates used to display those nodes are inefficient
Maybe you should look into refactoring somewhere else and not just adding caches...

Principal Consultant International Business
Member of the Community Project Board

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 11:34:24
Script start
Timing: Jan 18 2025 11:34:24
Module start 'layout'
Timing: Jan 18 2025 11:34:24
Module start 'content'
Timing: Jan 18 2025 11:34:24
Module end 'content'
Timing: Jan 18 2025 11:34:24
Script end

Main resources:

Total runtime0.6554 sec
Peak memory usage4,096.0000 KB
Database Queries65

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0089 589.0391152.6250
Module start 'layout' 0.00890.0039 741.664139.4453
Module start 'content' 0.01290.6407 781.1094617.4609
Module end 'content' 0.65360.0017 1,398.570316.1719
Script end 0.6553  1,414.7422 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00370.5649160.0002
Check MTime0.00160.2475160.0001
Mysql Total
Database connection0.00270.409110.0027
Mysqli_queries0.580988.6365650.0089
Looping result0.00070.1119630.0000
Template Total0.613993.720.3070
Template load0.00280.425120.0014
Template processing0.611193.250920.3056
Template load and register function0.00010.015610.0001
states
state_id_array0.00120.181410.0012
state_identifier_array0.00100.146020.0005
Override
Cache load0.00240.3673340.0001
Sytem overhead
Fetch class attribute can translate value0.00070.109530.0002
Fetch class attribute name0.00140.206480.0002
XML
Image XML parsing0.00150.223830.0005
class_abstraction
Instantiating content class attribute0.00000.0026100.0000
General
dbfile0.00741.1322290.0003
String conversion0.00000.001740.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
5content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
5content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
8content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 24
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs