Forums / Setup & design / Special Caching functionallity needed

Special Caching functionallity needed

Author Message

Frode Marton Meling

Monday 26 January 2004 12:56:24 am

Hello
I have a question on how to resolv this in the best way.

I have a large class containing alot of attributes and I have changed the template showing the objects of the class. I have redone the folder template for the folder and also overridden the line.tpl (node_view_gui) called from the folder.tpl.

My problem:
- Everything works, but I have all objects (over 200) displayed in a large grid (like in Excel) or table if you want. By adding som DHTML i have added functionality to sort by coloumn and everything..
- The load time/generate time is good when cache is done, but when just one of the objects change, the hole page needs to be regenerated.

Can I solve this with caching blocks, so the hole table is not generated as soon as a object is edited?

Will something like this work?
grabbed from the folder.tpl override:
...(This is how it is today)
{section name=Child loop=$children sequence=array(bglight,bgdark)}
<tr>{node_view_gui view=line content_node=$Child:item}</tr>
{/section}
...
...(This is how I wonder if will work
{section name=Child loop=$children sequence=array(bglight,bgdark)}
{cache-block keys=$Child:item.node_id}
<tr>{node_view_gui view=line content_node=$Child:item}</tr>
{/cache-block}
{/section}
...
Is this how the cache-block is intended to be used or is this overkill (since it will be generated over 200 cacheblocks)
Hope some of you can give me good ideas..

Frode

Frode Marton Meling

Monday 26 January 2004 1:48:29 am

Just to inform:
I tried this on my 3.2-1 version:
{section name=Child loop=$children sequence=array(bglight,bgdark)}
{cache-block keys=$Child:item.node_id}
<tr>{node_view_gui view=line content_node=$Child:item}</tr>
{/cache-block}
{/section}

It caches, but when I re publish an object it still generates a hole new table

Frode

Bjørn Reiten

Wednesday 28 January 2004 2:53:32 am

This will not work as intended.

The cache blocks are expired compared to a timestamp (expiry.php) in the cache directory. When update an article, this timestamp will be updated, and every cache-blocks which are older than this one, will be expired.

In this case will cache-blocks in a section here, create just more overhead.

You can however use the parameter ignore_content_expiry and expiry to not expire all the cache at once.

ignore_content_expiry will not be expired, even if an object is published
expiry=120 will set that the cache-block should expire in 120 seconds. If you change this value for each cache-block, and have some visits on your site, each cache block will be regenerated at a different time.

But, here you'll need to clear all cache from the admininterface, or with the clearcache script to be shure that all the content apears at once (since you can set the delay on the cacheblock).

Bjørn

Frode Marton Meling

Wednesday 28 January 2004 4:10:07 am

It may be easier for me to make a cron job to update this page. How is this done?

By this I mean that users always read from cache and a php script updates the cachefile from cron.

Frode

Bård Farstad

Monday 02 February 2004 6:33:05 am

To make a cron job update this page is a good idèa. The simplest way of doing this would be to use apache rewrite rules to something like:

 RewriteEngine On
 RewriteCond   %{REQUEST_METHOD}       !^POST$
 RewriteCond   /home/bf/public_html/3.3/static$1/index.html -f
 RewriteRule   ^(.*)$  /eznostatic$1/index.html [L]
 RewriteRule !\.(gif|css|jpg|png|jar|ico|js)$ /index.php

This rewrite rule will check if a static version of the page exists in the folder static/ under the eZ publish root ( /home/bf/public_html/3.3/ ). If it's found it serves the static page.

To regenerate this page you could simply do a wget to the file and store it in that directory. E.g. the url www.example.com/myfolder/article would look for a static file in static/myfolder/article/index.html. So this could be generated by doing a "wget www.example.com/myfolder/article" which would store the content in static/myfolder/article/index.html. This could then be run e.g. every 5/10/30 minutes.

Also see that sitecopy contribution from Denis, which does a setup like this.

Note: you need to have a different virtualhost without this rewriterule which is used for the cron job to do the wget ( since the normal site will only serve the cached static version of the page ).

Note2: this only works if you don't have different content for every user. E.g. a login box with username.

If you don't want to use rewrite rules you still can run the cronjob, However the page will only be fetched and the eZ publish internal cache will be stored. If a user requests this page before the cronjob he will still get the slow page. 3.4 will support caching on publishing, but this is not yet available.

I hope this answered your question.

--bård

Documentation: http://ez.no/doc