Forums / Developer / CacheBlock problem

CacheBlock problem

Author Message

Julien Plesniak

Monday 06 August 2007 6:53:44 am

Hello, i have a problem with the cache.

I have a template which contain this code:

{if not(ezhttp('modif'))}
   {def $modific = 0}
{else}
   {def $modific = 1}
{/if}

{cache-block keys=array($uri_string, $i, $modific)}
{if $i|eq(0)}
    Text A
{else}
    {if $modific|eq(0)}
       Text B
    {else}
       Text C
    {/if}
{/if}
{/cache-block}

When i go to mywebsite, i have $i = 0 so I see the "text A", but when i click on a button (wich switch $i = 1 in database) i didn't see the "text B" but always "text A".

When i disabled the cache, the site works perfectly , i see TextB.

i try to add a cache block (in the example) but it doesnt work.

Whats the problem?

Thanks for help

André R.

Monday 06 August 2007 9:10:16 am

Could you show how $i is defined ?

Btw there are some bugs in the code:
1. ezhttp produce error if the variable you are getting is unset.
2. I hope this is only example code, since that cache block is a wast of resources
(there is no point in caching two if's)

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

Xavier Dutoit

Monday 06 August 2007 9:14:20 am

Is it a template for a view (full...) ? in that case, you have to disable the cache for this template (set ttl = 0 ) otherwise the node is cached, and it doesn't take into account the cache-block in the template.

X+

http://www.sydesy.com

Julien Plesniak

Monday 06 August 2007 11:39:17 pm

Hello, i add before my cache block

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

and it work perfectly. Thanks :)

Ps: Yes André, it is an example, reduced to be read on the forum ;)