Problem with cache-block function in a template override

Author Message

Daniele Nocentini

Sunday 23 March 2008 9:17:28 am

Hello!

In my website I have frontpage with some box with news and others, in one of this box I need to display some nodes according to the current date, I use an override template for content/view/embed in this template I have a code to fetch nodes according to current date but with template cache and content cache on my frontpage never update, I try to put
{set-block scope=root variable=cache_ttl}0{/set-block} and cache-block but does not work, maybe I'm not understand the correct usage for this template operator.
someone can help me?
the template I use is override:

content/view/embed.tpl

and this is my code


{def $timestamp=currentdate()}
<h1>Current date/time: {$timestamp|l10n( 'shortdatetime' )}</h1>


{def $today=currentdate()
	 $prossime_gare=fetch( 'content', 'list', hash( 'parent_node_id', $object.main_node_id,
									                'attribute_filter', array( array( 545, '>=', $today )),
									                'class_filter_type', 'include',
									                'class_filter_array', array('scheda_gara') ))
									   
 	 $ultime_gare=fetch( 'content', 'list', hash( 'parent_node_id', $object.main_node_id,
										          'attribute_filter', array( array( 545, '<=', $today )),
										          'class_filter_type', 'include',
										          'class_filter_array', array('scheda_gara') )) }


{if gt($prossime_gare|extract_left(1)|count(),0)}
<div class="box-grey">
	<div class="box-head"><h3><span>Prossima gara</span></h3></div>
	<div class="box-body">
	{foreach $prossime_gare|extract_left(1) as $prossima_gara}
		{content_view_gui view=embed content_object=fetch( 'content', 'object', hash( 'object_id', $prossima_gara.contentobject_id ) )}
	{/foreach}
	</div>
</div>		
{/if}
{if gt($ultime_gare|extract_right(1)|count(),0)}
<div class="box-grey">
	<div class="box-head"><h3><span>Ultima gara</span></h3></div>
	<div class="box-body">
	{foreach $ultime_gare|extract_right(1) as $ultima_gara}
		{content_view_gui view=embed content_object=fetch( 'content', 'object', hash( 'object_id', $ultima_gara.contentobject_id ) )}
	{/foreach}
	</div>
</div>	
{/if}

Antica Bottega Digitale srl
http://www.abd.it

André R.

Sunday 23 March 2008 10:24:15 am

{set-block scope=global variable=cache_ttl}0{/set-block}

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

Daniele Nocentini

Tuesday 25 March 2008 7:28:26 am

Thanks andrè for tips, now works.
But I have another cache understanding problem, I have also a list of file excel file download from fecth in a folder on content structure, I want to show the number of download but with template compile on and content cache on this count does not update.

this is my code for the link download inside a foreach:

{cache-block expiry=20 keys=$child.data_map.file.content.main_node.data_map.file.content.original_filename|urlencode}
		<a href={concat( 'content/download/', $child.data_map.file.content.main_node.data_map.file.contentobject_id, '/', $child.data_map.file.content.main_node.data_map.file.id,'/version/', $child.data_map.file.content.main_node.data_map.file.version , '/file/', $child.data_map.file.content.main_node.data_map.file.content.original_filename|urlencode )|ezurl}><img src={"download.png"|ezimage} border="0" alt="{$child.data_map.file.content.main_node.data_map.file.content.download_count} download" title="{$child.data_map.file.content.main_node.data_map.file.content.download_count} download" /></a>
		&nbsp;{$child.data_map.file.content.main_node.data_map.file.content.download_count}
		{/cache-block}

Antica Bottega Digitale srl
http://www.abd.it

André R.

Wednesday 26 March 2008 11:20:56 am

First of all, you should remove that cache block (cache blocks introduce overhead as well, so you should not use them inside a foreach like that), you problem is probably that this code is inside another cache block or view cache.

Introduction to cache blocks:

{cache-block expiry=3600 ignore_content_expiry}
    {cache-block expiry=20}
    This code will update every hour {currentdate()|l10n( 'shortdatetime' )}
    {/cache-block}
{/cache-block}

Same goes for content view cache ( inside a view/full node template ):

{set-block scope=global variable=cache_ttl}3600{/set-block}
    {cache-block expiry=20}
    This code will update every hour {currentdate()|l10n( 'shortdatetime' )}, unless this node is edited!
    {/cache-block}

The text will only update if the node is edited if cache_ttl is not explicit set, and text will update every 20 seconds if cache_ttl is set to 0 (disable view cache).

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

Daniele Nocentini

Monday 12 May 2008 2:09:44 am

If possible to not cached a part of template like this:

{non-cache-block}

bla bla bla

{/non-cache-block}

Antica Bottega Digitale srl
http://www.abd.it

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 19 2025 01:06:49
Script start
Timing: Jan 19 2025 01:06:49
Module start 'layout'
Timing: Jan 19 2025 01:06:49
Module start 'content'
Timing: Jan 19 2025 01:06:49
Module end 'content'
Timing: Jan 19 2025 01:06:49
Script end

Main resources:

Total runtime0.7793 sec
Peak memory usage4,096.0000 KB
Database Queries63

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0062 590.8438152.6563
Module start 'layout' 0.00620.0030 743.500039.5078
Module start 'content' 0.00920.7688 783.0078581.7969
Module end 'content' 0.77800.0013 1,364.804720.0938
Script end 0.7793  1,384.8984 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00320.4101160.0002
Check MTime0.00130.1706160.0001
Mysql Total
Database connection0.00090.117410.0009
Mysqli_queries0.718192.1395630.0114
Looping result0.00080.1057610.0000
Template Total0.746395.820.3732
Template load0.00270.341420.0013
Template processing0.743695.418820.3718
Template load and register function0.00010.014010.0001
states
state_id_array0.00170.224210.0017
state_identifier_array0.00150.194920.0008
Override
Cache load0.00220.2820350.0001
Sytem overhead
Fetch class attribute can translate value0.00060.074020.0003
Fetch class attribute name0.00130.170070.0002
XML
Image XML parsing0.00110.136320.0005
class_abstraction
Instantiating content class attribute0.00000.0029100.0000
General
dbfile0.00090.1144230.0000
String conversion0.00000.000940.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/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 26
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs