Forums / General / Remove cache for random article?

Remove cache for random article?

Author Message

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

Steven Stieng

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?

Gaetano Giunta

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

Principal Consultant International Business
Member of the Community Project Board

Steven Stieng

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

Steven Stieng

Friday 28 May 2010 7:56:41 am

ok, thanks :)

Trying to set this post as 'answered' - but not much is happening.... :-/

 

eZ debug

Timing: Jan 29 2025 13:47:45
Script start
Timing: Jan 29 2025 13:47:45
Module start 'content'
Timing: Jan 29 2025 13:47:45
Module end 'content'
Timing: Jan 29 2025 13:47:45
Script end

Main resources:

Total runtime0.0163 sec
Peak memory usage2,048.0000 KB
Database Queries4

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0053 587.9219180.8438
Module start 'content' 0.00530.0048 768.7656101.9453
Module end 'content' 0.01010.0061 870.710978.7031
Script end 0.0162  949.4141 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002112.6141120.0002
Check MTime0.00105.8886120.0001
Mysql Total
Database connection0.00053.221310.0005
Mysqli_queries0.002414.896040.0006
Looping result0.00000.099720.0000
Template Total0.005835.610.0058
Template load0.00095.322910.0009
Template processing0.004930.261010.0049
Override
Cache load0.00063.804610.0006
General
dbfile0.002314.1310100.0002
String conversion0.00000.036630.0000
Note: percentages do not add up to 100% because some accumulators overlap

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