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