Forums / Developer / User parameters cause cache trouble [solved]

User parameters cause cache trouble [solved]

Author Message

Tobias Vogel

Wednesday 31 October 2007 10:07:09 am

Hi all,

I made a generic newsticker-template (included in other node/view/full templates), that changes it's content depending on user parameters, e.g.:

.../index.php/siteaccess/news/overview/(mode)/archive/(year)/2005

When I tested it on a live installation (ezp 3.10) with template and view caching enabled, the page only gets generated once, using the parameters passed with that request. Any further requests with different custom parameters set (e.g. /(year)/2006) just return the first (wrong) version from the cache.

According to the following documentation page (last paragraph), the cache system should automatically be aware of user parameters and keep different versions of the page:
http://ez.no/ezpublish/documentation/customization/custom_design/user_specified_parameters

This obvoiusly doesn't work. I already tried to set the TTL to 0 and/or use custom cache blocks, but none of the measures had any affect. Ezpublish will always serve the version of the first request.

Do you have any additional hints or ideas, what is going wrong here?

Tobias Vogel

Friday 02 November 2007 3:14:27 am

If I set

TemplateCache=disabled

the problem is gone. Anyway that doesn't seem to be the right solution to me.

I tried custom cache-blocks in the include template:

{set-block scope=global variable=cache_ttl}0{/set-block}
{cache-block keys=array($node,$view_parameters)}
...
[template code]
...
{/cache-block}

These settings don't have any effect wherever I place them, even in the pagelyout.

Sebastiaan van der Vliet

Friday 02 November 2007 9:30:18 am

Hi Tobias, did you also try putting {cache-block expiry=0}include file{/cache-block}?

Certified eZ publish developer with over 9 years of eZ publish experience. Available for challenging eZ publish projects as a technical consultant, project manager, trouble shooter or strategic advisor.

André R.

Friday 02 November 2007 10:14:05 am

{set-block scope=global variable=cache_ttl}0{/set-block}

Is for view cache ( aka content view cache, as in cache for the content/view module view), so has no effect on cache blocks.

As for setting expiry=0, this is what happens(from the doc):

A value of zero will produce a cache block that will never expire.

the reason it doesn't work is that the keys parameter only supports 1 level deep arrays.
It will not understand the $node or $view_parameters objects!

You can use $module_result.uri ( url + view params + view param values) if this is in a pagelayout:

{cache-block keys=$module_result.uri}
...
[template code]
...
{/cache-block}

You need to know what params are going to be used if this is in a node template:

{def $user_id = first_set($view_parameters.id, '')}
{cache-block keys=array($node.node_id, $user_id, $view_parameters.offset)}
...
[template code]
...
{/cache-block}

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

Tobias Vogel

Monday 05 November 2007 6:11:42 am

Wow, thanks for your explanation, helped me a lot further and I also found the reason for some strange behaviour:

Somewhere in the middle of the pagelayout there was another cache-definition:

{cache-block keys=array($uri_string, $basket_is_empty, $user_hash)}

IMHO I read somewhere, that ezpublish can't keep track of children in a nested cache-block structure, so this artifact cache-block additionally interfered with my tests.