Forums / Setup & design / Weird Caching problem

Weird Caching problem

Author Message

Massimo Sanna

Friday 27 January 2006 1:35:30 am

Hi there, I'm actually optimizing the speed of a ez3 website. I activated every option in site.ini (templatecompile, viewcaching, templatecompress, templateoptimize and so on).
It works really _REALLY_ fast and smoothly, but there's a problem.
I created a left menu navigation which shows the childrens under the current node, and if you arrived at the last level it keeps on showing the other elements at the same level.
If I enable the TemplateCompile option, it works ok the first time it loads it, and until the cache expires you can see this menu, then after 2 hours if you try to open again one of the pages you no longer see the left menu.
I guess it could be a key problem in cache-block or something like that?

This is the code snippet which doesn't work:

{cache-block keys=array($leftMenus, $module_result.node_id)}
					<div id="leftmenu">
<ul id="sottosezioni">

{def $conteggio=fetch('content', 'list_count', hash('parent_node_id', $module_result.node_id ) )}
{if $conteggio|ne(0)}
	{let leftMenus=treemenu($module_result.path,$module_result.node_id,true(),sub($node.depth,1),1)}
	{section name=leftMenu loop=$leftMenus}
	{section show=$leftMenu:item.id|eq($module_result.node_id)}
	<li><a href={$leftMenu:item.url_alias|ezurl} title="{$leftMenu:item.text}" class="active">{$leftMenu:item.text}</a></li>
	{section-else}
	<li><a href={$leftMenu:item.url_alias|ezurl} title="{$leftMenu:item.text}">{$leftMenu:item.text}</a></li>
	{/section}
	{/section}
	{/let}
{else}
	{let leftMenus=treemenu($module_result.path,$module_result.node_id,true(),sub($node.depth,2),1)}
	{section name=leftMenu loop=$leftMenus}
	{section show=$leftMenu:item.id|eq($module_result.node_id)}
	<li><a href={$leftMenu:item.url_alias|ezurl} title="{$leftMenu:item.text}" class="active">{$leftMenu:item.text}</a></li>
	{section-else}
	<li><a href={$leftMenu:item.url_alias|ezurl} title="{$leftMenu:item.text}">{$leftMenu:item.text}</a></li>
	{/section}
	{/section}
	{/let}	
{/if}
</ul>
					</div>
{/cache-block}

Grenland Web (Jan Kudlicka)

Friday 27 January 2006 2:28:34 am

Hi Massimo,

the problem with your code is the following:

In the cache block you are using variable $node (for example in sub($node.depth,1)). This variable does not exist when the <i>content/view</i> view will use the cached version of the page (understand the result from the <i>content/view</i> view = the output of <i>/node/view/full.tpl</i> or its override).

When you remove the caches and you are accessing a page the first time, eZp has to render <i>/node/view/full.tpl</i> (or its override) first and the template system creates $node (which you are using in the template). The rendered page is then stored in the cache and the template system continues with rendering <i>pagelayout.tpl</i>. Because the cache-block does not exist, the code is processed and everything is fine because the template system still remembers the $node variable.

But once the cache-block has expired (= in 2 hours) and the template systems tries to process the code (of the cache-block) once again, the cached version of the page is used and that's why there is no $node.

<b>Solution: do not use $node.depth. Use $module_result.content_info.node_depth instead.</b>

Recommendation: there is no need to expire cache block in the time domain. Use expiry="0" in the cache-block. The cache-block will expiry only when any content on the site is (re-)published. (You can go even further and try to use the subtree_expiry parameter.)

Jan Kudlicka | System Developer @ Grenland Web | http://www.grenlandweb.no

Massimo Sanna

Friday 27 January 2006 2:32:49 am

Thank you thank you!
You solved my problem! Now it works ok!
And the trick of putting expiry=0 works flawlessly.
I also planned to use the subtree_expiry feature on some items which could benefit from it :)
I will pay you a beer hehe

Max

eZ debug

Timing: Jan 18 2025 10:27:25
Script start
Timing: Jan 18 2025 10:27:25
Module start 'content'
Timing: Jan 18 2025 10:27:26
Module end 'content'
Timing: Jan 18 2025 10:27:26
Script end

Main resources:

Total runtime1.2588 sec
Peak memory usage4,096.0000 KB
Database Queries194

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0088 587.7031180.8438
Module start 'content' 0.00881.1044 768.5469549.3672
Module end 'content' 1.11320.1455 1,317.9141336.7578
Script end 1.2587  1,654.6719 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00500.3940210.0002
Check MTime0.00200.1598210.0001
Mysql Total
Database connection0.00090.071510.0009
Mysqli_queries1.177493.53351940.0061
Looping result0.00210.16411920.0000
Template Total1.215496.620.6077
Template load0.00360.285720.0018
Template processing1.211896.267120.6059
Template load and register function0.00010.008010.0001
states
state_id_array0.00110.089210.0011
state_identifier_array0.00210.163620.0010
Override
Cache load0.00260.2090270.0001
Sytem overhead
Fetch class attribute can translate value0.00160.125530.0005
Fetch class attribute name0.00110.088540.0003
XML
Image XML parsing0.00090.074730.0003
class_abstraction
Instantiating content class attribute0.00000.000850.0000
General
dbfile0.00300.2394270.0001
String conversion0.00000.000830.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
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
3content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 13
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs