Forums / Setup & design / Problem with cache-block function in a template override

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

eZ debug

Timing: Jan 19 2025 15:12:54
Script start
Timing: Jan 19 2025 15:12:54
Module start 'content'
Timing: Jan 19 2025 15:12:54
Module end 'content'
Timing: Jan 19 2025 15:12:54
Script end

Main resources:

Total runtime0.1474 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.0080 589.2109180.7969
Module start 'content' 0.00800.0054 770.0078102.1016
Module end 'content' 0.01340.1338 872.1094533.4219
Script end 0.1473  1,405.5313 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00352.3530200.0002
Check MTime0.00130.8973200.0001
Mysql Total
Database connection0.00120.825810.0012
Mysqli_queries0.103870.43651410.0007
Looping result0.00120.79971390.0000
Template Total0.133590.610.1335
Template load0.00090.599110.0009
Template processing0.132689.979510.1326
Override
Cache load0.00060.410610.0006
Sytem overhead
Fetch class attribute can translate value0.00070.470810.0007
XML
Image XML parsing0.00030.171010.0003
General
dbfile0.00332.2564200.0002
String conversion0.00000.005530.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.0001 secs