Forums / General / Remove cache for random article?
Steven Stieng
Thursday 27 May 2010 7:48:37 am
I have the following code which returns a random article:
{def $random_articles=fetch('content', 'list', hash('parent_node_id', 72, 'offset', rand(0,4), 'limit', 1))} {foreach $random_articles as $article} {$article.name|wash} {/foreach}
My problem is that a new article is not loaded when I hit the F5, because the page is cached.
I've even tried removing {cache-block}, but that didn't help.
How can I get around this problem?
Gaetano Giunta
Thursday 27 May 2010 9:12:45 am
If this is inside a node view template, you should set the cache_ttl to 0 (or a few seconds). see http://ez.no/doc/ez_publish/technical_manual/4_x/reference/template_functions/variables/set_block
Principal Consultant International Business Member of the Community Project Board
Friday 28 May 2010 12:07:50 am
But won't
{set-block scope=global variable=cache_ttl}0{/set-block}
turn of caching for the entire page?
Friday 28 May 2010 12:27:50 am
Indeed.
Maybe that's not what you want - but you did not specify a lot of detail in your original post...
Probably you can achieve what you want by:
- setting cache_ttl to disable view cache for entire page
- use a cache block around the part of the template that displays current node (using subtree_expiry as key)
- optionally use a 2nd cache block arolund your random articles list
Friday 28 May 2010 12:51:16 am
The random article is shown on the front page, in a section set for news.The other elements may be cached, but not the news box - since a new article should be loaded foreach page reload.
So if I put a second cach block around my news container, and inside this I put the cache_ttl, then I should be turning off caching for just that part?
André R.
Friday 28 May 2010 1:27:06 am
No it turns of cache for the whole view*, cache_ttl only affects view cache as you have on content/view, it will not affect cach-blocks in the view or in your pagelayout.This is why setting it to for instance 30 or 60 seconds might be enough for you, as in do you really need a new item on every single page reload? If you do, consider preloading something like ten random items at a time and use javascript to select one of them on every single load, or load the whole block with ajax or something.
*view: the content ($module_result.content) on your page that is relevant to the url your on, excluding dynamic headers, menues, footer and anything else from your pagelayout.Only content/view/.. ur's are cached with view cache, hence the full name of the cache "Content 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
Friday 28 May 2010 7:56:41 am
ok, thanks :)
Trying to set this post as 'answered' - but not much is happening.... :-/