Share » Forums » Developer » Viewcaching and cache-block - when to...

Viewcaching and cache-block - when to use?

Viewcaching and cache-block - when to use?

Sunday 22 February 2004 7:48:14 am - 8 replies

Author Message

Bård Farstad

Monday 23 February 2004 4:57:22 am

ViewCache should always be enabled, unless when you do template development. Cache-block should be used in pagelayout to minimize the processing time on 2nd time view.

You should definetly combine these, but you should never use cache-blocks in the overrides for full.tpl ( article, folder.. ). There can of-course be special cases where you need to do this, but as a general rule you should only use cache-block statements in the pagelayout.tpl file.

ViewCache is storing of the HTML output from the article view, folder view, product view etc. This means that the second time you view an article it's fetched from cache. Only the article content is fetched from the cache.

--bård

Documentation: http://ez.no/doc

Nicklas Lundgren

Friday 27 February 2004 3:43:28 am

Thanks for the reply, Bård!

However, I still have some trouble regarding this.

In some sites I use random images. For instance, on a front page I want the main image to be randomly selected from a group of five images.
I now manage this in the following way:
1. I make a fetch from the folder where the images exist and run a "shuffle" operator on the resulting array.
2. I get the first image in the array and show it on the page.

This works if I place cache-block around the image, like in the code below:
---------------------------
{cache-block keys=array('random_image_frontpage',$image:item.node_id)}
<td valign="top" width="{$image:item.contentobject_version_object.data_map.image.content[large].width}" height="{$image:item.contentobject_version_object.data_map.image.content[large].height}">{attribute_view_gui attribute=$image:item.contentobject_version_object.data_map.image image_class="large"}</td>
{/cache-block}
----------------------------

However - when I activate viewcache, I get the same image on every page load.

Am I doing something stupid? In that case I would appreciate some guidance.

Kind regards
Nicklas Lundgren

Bård Farstad

Friday 27 February 2004 4:10:49 am

Using cache blocks with viewcache does not make sense in this case since eZ publish will not process the template ( where the cache block is ) when view caching is enabled.

If you want/need to use the cache block inside the viewcache you should disable the viewcache for that template only ( done by setting a template variable ).

--bård

Documentation: http://ez.no/doc

Willie Seabrook

Wednesday 03 March 2004 2:58:33 pm

May I ask for clarification on this as I was wondering... What *exactly* is the difference between ViewCaching and cache-block? Both seem to do the same thing - store a compiled template as html....

Regards,
Willie

Paul Forsyth

Thursday 04 March 2004 12:22:40 am

I think its simply the difference between global and local. cache-block gives you fine control over local elements, while viewcache caches all content/view elements (I think...). Therefore you can use cache-block to switch off viewcaching locally... Or use it to enable caching locally if the global setting is off. This is my understanding, but it may be wrong.

We probably need more examples of usage...

paul

Jan Borsodi

Thursday 04 March 2004 2:48:12 am

cache-block is a general purpose caching mechanism for text blocks. It basicly stores the resulting text (or html) in a file and reloads that the next time. It also has expiration based on time and content publishing.

View caching on the other has more logic. For the first it has a predefined set of cache keys set. It also stores extra information in the cache files, sucb as override keys etc. which are restored the next time.
View caching is also integrated deeper with the publishing process, meaning that publishing will actually clear all related view cache files.

You should use cache-block in pagelayout and other non-content view templates. Using cache-block in for instance full.tpl generally has no speed increase.

--
Amos

Documentation: http://ez.no/ez_publish/documentation
FAQ: http://ez.no/ez_publish/documentation/faq

Paul Borgermans

Thursday 04 March 2004 3:26:19 am

Perhaps a small addition to Jan's post:

I do regularly use cache blocks in view templates for certain classes where the view depends on for example user preferences and custom template variables. Here the view cache is turned off with a set-block statement in the class_view_mode template (so global view ccahing is still on). The various components are then wrapped in specific cache-blocks to allow for some speedup (slightly slower than with normal view caching).

An example of use is wether the user wants to see the audit trail (version history).

The downside is of course a doubling/tripling in cache files .... but the server we use is dimensioned for that purpose.

It is also for these cases that I welcome the speedups in non-cached template things in 3.4 ... sometimes page rendering is dynamic in all senses.

-paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Rami Grossman

Tuesday 22 June 2004 7:54:23 am

How exactly do I disable the view caching on specific tpl file?
What is the syntax?

Tanks, Rami

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu