Forums / Developer / Cache-block problem

Cache-block problem

Author Message

Salvatore Guarino

Thursday 03 May 2007 6:25:40 am

Hi, I have a strange problem with caching. I enabled on my site.ini.append.php the following settings:

[ContentSettings]
ViewCaching=enabled
[TemplateSettings]
TemplateCache=enabled
TemplateCompile=enabled

In my pagelayout.tpl I have a cache-block with a variable that changes a div id when the section changes:

{cache-block keys=$uri_string}

{def $section=fetch( 'section', 'object', hash( 'section_id', $node.object.section_id ) )}

    <div id="topcontent-{$section.name|wash}">
...
   </div>
{/cache-block}

If I clear the cache, the site works and if I navigate to differents sections the div id changes. But, sometimes, it doesn't work at all because div id doesn't change untill I clear the cache again. eZpublish version is 3.7.2.

Thank you!

Nabil Alimi

Thursday 03 May 2007 7:05:43 am

Hi Salvatore,

You're facing the very unfamous $node availibility issue.
Until you fetch the <b>$node</b> by yourself, with something like :

 {def $node=fetch( content , node , hash( node_id , $module_result.node_id ) 


you should <b>never</b> use the $node variable in pagelayout. It is an issue that has been <i>solved</i> in recent eZpublish releases by totally removing the $node variable thus making it no longer possible to do what you're trying.
In previous versions, the $node was available on first-time access of a node that's why your piece of code works on your 3.7.2 eZpublish version.

So here, as I've suggested earlier, you'll need to fetch the $node before using it.

:)

Best regards.

My blog : http://www.starnab.com/ezpublish / http://www.starnab.com/ / http://www.assiki-consulting.com
eZ Publish Freelance developper. Feel free to contact me +33 674 367 057
nabil at assiki d0t fr

Salvatore Guarino

Thursday 03 May 2007 7:27:37 am

Hi Nabil,
thank you very very much for your respone, but I don't understand what do you mean with <i>"you'll need to fetch the $node before using it"</i>. Could you give me an example?
Bye, Salvatore

Nabil Alimi

Thursday 03 May 2007 9:26:30 am

Salvatore,

I meant that you need to fetch the node with something similar to the piece of code I pasted up there. Try this :

{cache-block keys=$uri_string}

{def  $node=fetch( 'content' , 'node' , hash( node_id , $module_result.node_id ) ) 
       $section=fetch( 'section', 'object', hash( 'section_id', $node.object.section_id ) )}
   <div id="topcontent-{$section.name|wash}">
...
  </div>
{/cache-block}

In case you need to access the $node somewhere else in your template, you should put the node fetch outside of the cache-block.

:)

My blog : http://www.starnab.com/ezpublish / http://www.starnab.com/ / http://www.assiki-consulting.com
eZ Publish Freelance developper. Feel free to contact me +33 674 367 057
nabil at assiki d0t fr

Atle Pedersen

Friday 04 May 2007 1:06:28 am

The point/problem is that you're not always showing a node. Sometimes you show views from other modules, for example the login screen. In these cases having a $node variable is meaningless.

Therefor you should also check for the existence of $module_result.node_id before using it.

Read more on this friendly page:
http://ez.no/doc/ez_publish/technical_manual/3_8/templates/the_pagelayout/variables_in_pagelayout

eZ debug

Timing: Jan 21 2025 16:10:33
Script start
Timing: Jan 21 2025 16:10:33
Module start 'content'
Timing: Jan 21 2025 16:10:33
Module end 'content'
Timing: Jan 21 2025 16:10:33
Script end

Main resources:

Total runtime0.2067 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0089 593.4453180.8438
Module start 'content' 0.00890.0149 774.2891101.9609
Module end 'content' 0.02380.1828 876.2500526.7344
Script end 0.2066  1,402.9844 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00401.9403200.0002
Check MTime0.00150.7107200.0001
Mysql Total
Database connection0.00080.366710.0008
Mysqli_queries0.133064.36331410.0009
Looping result0.00140.68141390.0000
Template Total0.182188.110.1821
Template load0.00130.621810.0013
Template processing0.180887.479910.1808
Override
Cache load0.00090.414610.0009
Sytem overhead
Fetch class attribute can translate value0.00090.447510.0009
XML
Image XML parsing0.00020.113210.0002
General
dbfile0.01436.9017200.0007
String conversion0.00000.003930.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.0002 secs