Forums / Setup & design / Implementing caching- cache-block questions

Implementing caching- cache-block questions

Author Message

arthur foelsche

Tuesday 13 May 2003 4:12:32 am

I have some questions about implementing caching. I've got my site fairly much done, but am noticing that I really need to figure out ways to improve the speed of the front page loads, as this page has to dig through all the content in the database in order to construct itself. I looked at the manual description of the cache-block function, but haven't figured out if i'm implementing it correctly, as i haven't seen any speed improvements (yes, i have turned on view caching in site.ini.php)

here's the code i'm using in the template:
20 most recent stories: <br>
{let test=fetch( 'content',
'list',
hash(parent_node_id, 158, class_filter_type, "include", class_filter_array, array(2), "sort_by", array("modified", false()), "depth", 0))
}
<table> {cache-block keys=$test}
{section name=Child loop=$test max=20}
<tr><td valign="top"><font size=-1>{$Child:item.data_map.article_date.data_int|l10n(date)}</td>
<td><font size=-1><a href={concat("/content/view/full/",$Child:item.node_id)|ezurl}>{attribute_view_gui attribute=$Child:item.data_map.pagetitle}</a>
<i>{attribute_view_gui attribute=$Child:item.data_map.article_location}</i></td></tr>{/cache-block}
{/section}
</table>
{/let}

have i used cache-block correctly?

I guess the other question i have is how to move this into a {$module_result.content} output. The way the site is configured is to have a front page which has a listing of all the recent articles (and navigation to older pages) and link through to specific sections and articles which display by region. Basically a newswire which links through to a categorized news wire. I'm using two different templates to do this- one for the front page and one to display either the region or the individual article. Is there a way to specify a different format for {$module_result.content} for different templates, but using the same module?

you can see what i'm doing here:
http://red.eggplantmedia.com/~fluoride/ez/index.php

beware, the page loads slowly!

Paul Forsyth

Tuesday 13 May 2003 5:33:58 am

arthur,

move the cache block to before the {let test=fetch... this will create a php cache of the results of the database calls - rather speeds things up :)

also, try this type of cache-block instruction. instead of caching just a single variation of your page it will work if you have dynamic pages that depend on changes between the node.

{cache-block keys=array('stories', $DesignKeys:used.node)}

finally, copy this contribution to your local ez files:

http://ez.no/developer/ez_publish_3/contributions/binshellclearcachesh_fix_to_clear_cacheblocks

this will allow you to clear cached files between tests... many a time ive wondered whats going on with cache off and finding cache being created...

paul

arthur foelsche

Tuesday 13 May 2003 8:25:47 am

wow- that made a huge different in page load times! Thanks! Its great to have people helping out in this fourm!

arthur foelsche

Tuesday 13 May 2003 4:20:57 pm

thanks for your help. I now understand what you were saying about wanting to use a different kind of caching for dynamic content- here you mentioned this call:

{cache-block keys=array('stories', $DesignKeys:used.node)}

should i replace stories and used.node with my particulars? or is this the format that i should use?

thanks again!

Paul Forsyth

Wednesday 14 May 2003 3:30:07 am

You should replace 'stories' with your own variables when you use the cache-block. Remember, this is an id so its not a good idea to use the same id more than once otherwise the id may index the same cached file...

Dont replace the $DesignKeys as that is an ez variable used when cache is on.

However, saying that, the particular example i gave works well since its allows your variable to be indexed. For example, if you have dynamic content for each node it may be seen as {stories, 1}, {stories, 2}, etc, and there will be a cached page for each.

One upshot of this is that more disk space will be used for cache (for each node) but you get better performance.

We are still experimenting with this so hopefully will learn the ins and outs with time :)

Paul

Paul Forsyth

Wednesday 14 May 2003 3:31:40 am

Try this program on this site:

http://www.joedog.org/siege/index.shtml

It allows you artificially stress your site and will give speeds on access. Ez use it i believe.

Paul