Forums / Setup & design / Random and cache...

Random and cache...

Author Message

Kristoffer Karlsson

Tuesday 03 July 2007 7:59:45 am

Please...

I have been fighting with this problem for a long time. I show a random article from node 252 on my frontpage. I have to clear the cache, or publish new content, to get a new article to be shown. Viewcaching in enabled.

The code from the template below. Can anyone give me a hint?

<div class="box-embgv">
		<div class="tl"><div class="tr"><div class="br"><div class="bl"><div class="box-content">
	{def $children = array()
	     $limit = 1
	     $offset = 0}

	{if is_set( $object_parameters.limit )}
		{set $limit = $object_parameters.limit}
	{/if}

	{if is_set( $object_parameters.offset )}
		{set $offset = $object_parameters.offset}
	{/if}
	
 
{set-block scope=root variable=cache_ttl}0{/set-block}
{cache-block expiry=0}


{def $max=fetch('content', 'tree_count', hash(parent_node_id, 252))} 
 {set $children=fetch( content, list, hash( 'parent_node_id', $object.main_node_id, 'limit', $limit, 'offset', rand(0,$max|sub(1)), 'sort_by', $object.main_node.sort_array ) ) }

	<div class="content-view-children float-break">
	{if $children|count()}
    {foreach $children as $child}
         
{node_view_gui view=line content_node=$child}
{/cache-block}
    {/foreach}
	{/if}
    </div>

_____________________________________
Blog: http://www.kristofferkarlsson.com
Website: http://www.spelkanalen.com

André R.

Tuesday 03 July 2007 9:24:24 am

Several issues:
first: from the cache-block expiry doc: 'A value of zero will produce a cache block that will never expire.'
second : {set-block scope=root variable=cache_ttl... should be in the top
third: the blocks are in wrong order, the ending of the cache block should be after the ending of the div
fourth: why are you using cache block when you don't want it to cache it ?

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

André R.

Tuesday 03 July 2007 9:27:01 am

And, this template is not a node template is it?
if it is included in another template (either as template include or as embed object) you also have to set cache_ttl on that template

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

Marco Zinn

Tuesday 03 July 2007 9:39:36 am

Hi,

please check these things:

1. Your foreach loop overlaps the cache-block boundaries. Please move the end of the foreach to withing the cache-block
2. {set-block scope=root variable=cache_ttl}0{/set-block} will set the Time To Live of the Content Cache for this node to 0, disabeling the cache. This should be the right way to do this. I had to use "scope=global" once to get it working, but i think, i had used an include file then.
3. {cache-block expiry=0} Means, that you define a cache-block around your output, which will last forever (99% sure, please check the docs on "cache-block"). You should remove this cache-block or set the expiry time to something usefull. Default is "2 hours", i think, maybe try expiry=30 , which means 30 seconds.

For testing, i'd recommend to remove the cache-block statements.

EDIT: :) I was on the phone, while i wrote this comment. I didn't want to duplicate André's entry, they just "overlapped in time" ;)

Marco
http://www.hyperroad-design.com

Kristoffer Karlsson

Thursday 05 July 2007 7:23:29 am

Thanks for your trying to help me.

I have moved the {set-block scope=root variable=cache_ttl}0{/set-block} to the top of the template and removed the cache-blocks.

It now works if I disable view-caching. If I turn it on I get the same article every time.

The code I posted is from the template horizontally_listed_subitems. I also added {set-block scope=root variable=cache_ttl}0{/set-block} to the pagelayout.tpl and the article-line.tpl, but with no result.

I am a beginner to ez and I am really greatful for your help.

_____________________________________
Blog: http://www.kristofferkarlsson.com
Website: http://www.spelkanalen.com

André R.

Thursday 05 July 2007 7:54:04 am

moving it to pagelayout does not help, cause pagelayout and it's included templates are not in the content view (its the stuff that surrounds it and makes out the layout).

So try setting scope=global instead in the original template like Marco mentioned.

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

Kristoffer Karlsson

Thursday 05 July 2007 11:39:33 pm

YES!!

It works. Thanks a lot for your help!

_____________________________________
Blog: http://www.kristofferkarlsson.com
Website: http://www.spelkanalen.com

eZ debug

Timing: Jan 18 2025 16:02:14
Script start
Timing: Jan 18 2025 16:02:14
Module start 'content'
Timing: Jan 18 2025 16:02:15
Module end 'content'
Timing: Jan 18 2025 16:02:15
Script end

Main resources:

Total runtime1.0150 sec
Peak memory usage4,096.0000 KB
Database Queries208

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0065 588.7422180.8438
Module start 'content' 0.00650.8700 769.5859645.7422
Module end 'content' 0.87650.1384 1,415.3281345.0859
Script end 1.0149  1,760.4141 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00410.4079210.0002
Check MTime0.00140.1423210.0001
Mysql Total
Database connection0.00070.065910.0007
Mysqli_queries0.930091.62762080.0045
Looping result0.00220.21212060.0000
Template Total0.985697.120.4928
Template load0.00250.243820.0012
Template processing0.983196.860620.4915
Template load and register function0.00010.010210.0001
states
state_id_array0.00090.084310.0009
state_identifier_array0.00090.085320.0004
Override
Cache load0.00210.2094430.0000
Sytem overhead
Fetch class attribute can translate value0.00130.131240.0003
Fetch class attribute name0.00120.1161100.0001
XML
Image XML parsing0.00230.223640.0006
class_abstraction
Instantiating content class attribute0.00000.0024140.0000
General
dbfile0.00410.4044400.0001
String conversion0.00000.000630.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
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
7content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
7content/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
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 28
 Number of unique templates used: 7

Time used to render debug report: 0.0003 secs