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.