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

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 21:05:12
Script start
Timing: Jan 18 2025 21:05:12
Module start 'layout'
Timing: Jan 18 2025 21:05:12
Module start 'content'
Timing: Jan 18 2025 21:05:13
Module end 'content'
Timing: Jan 18 2025 21:05:13
Script end

Main resources:

Total runtime0.8858 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.0060 587.8125152.6094
Module start 'layout' 0.00610.0032 740.421939.4141
Module start 'content' 0.00920.8752 779.8359620.2969
Module end 'content' 0.88440.0013 1,400.132816.1875
Script end 0.8858  1,416.3203 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00310.3451160.0002
Check MTime0.00140.1527160.0001
Mysql Total
Database connection0.00140.155510.0014
Mysqli_queries0.819992.5559650.0126
Looping result0.00070.0761630.0000
Template Total0.854196.420.4270
Template load0.00200.231320.0010
Template processing0.852096.186720.4260
Template load and register function0.00010.013310.0001
states
state_id_array0.00080.091110.0008
state_identifier_array0.00100.107320.0005
Override
Cache load0.00180.2026400.0000
Sytem overhead
Fetch class attribute can translate value0.00060.069030.0002
Fetch class attribute name0.00150.165080.0002
XML
Image XML parsing0.00420.476630.0014
class_abstraction
Instantiating content class attribute0.00000.0025100.0000
General
dbfile0.00420.4702290.0001
String conversion0.00000.001140.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
11content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
4content/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: 31
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs