Forums / Developer / node_view_gui and cache

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

eZ debug

Timing: Jan 30 2025 19:35:09
Script start
Timing: Jan 30 2025 19:35:09
Module start 'content'
Timing: Jan 30 2025 19:35:09
Module end 'content'
Timing: Jan 30 2025 19:35:09
Script end

Main resources:

Total runtime0.2172 sec
Peak memory usage8,192.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0084 587.9219370.3047
Module start 'content' 0.00840.0147 958.22661,005.6250
Module end 'content' 0.02310.1940 1,963.85163,894.1641
Script end 0.2171  5,858.0156 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00482.2281200.0002
Check MTime0.00140.6563200.0001
Mysql Total
Database connection0.00070.327910.0007
Mysqli_queries0.115152.98451410.0008
Looping result0.00160.71511390.0000
Template Total0.193589.110.1935
Template load0.00100.440710.0010
Template processing0.192688.663310.1926
Override
Cache load0.00060.268810.0006
Sytem overhead
Fetch class attribute can translate value0.00241.119310.0024
XML
Image XML parsing0.00030.152910.0003
General
dbfile0.00572.6305200.0003
String conversion0.00000.003330.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs