Forums / Developer / How the cache works with cache blocks (technical)

How the cache works with cache blocks (technical)

Author Message

Xavier Dutoit

Wednesday 13 September 2006 8:02:44 am

Hi,

It might or might not be related to the mysterious edit button that is displays on the wrong posts in ez forum. http://ez.no/community/forum/general/do_you_see_the_edit_button

I have a page layout with two differents part (say middle and left column) that are dynamic (ie differs from node to node).

in the pagelayout, I've got something like that :


main part

{$module_result.content}

<hr/>
other part

{cache-block keys=array($uri_string,$current_user.login)}
{section show=is_set($#extra)}
{$#extra}
{section-else}
generic part
{/section}
{/cache-block}

Then in the overrided full.tpl :

Bla bla in the main part

{set-block variable="extra" scope="global"}
bla bla in the other part
{/set-block}

The idea is that each template can set a different other part #extra for each user.

Unfortunately, it doesn't always work. If you change from one user to another and display the same page, it sometimes doesn't display the other part. Then, if you clear all the caches, it displays the correct one again, but other users might get the wrong other part, on that node or another.

It has different reactions if the template is complied or isn't, both with problem. It is very hard to reproduce, even by using several computers.

The only idea I have is that sometimes, the cache system decides that either the $module_result.content
or the extra block is already calculated and in cache and doesn't keep the two parts in sync.

Do you have any idea ? I'm seriously in the dark and that drives me nuts.

Am I wrong assuming that module.content is calculated once for every user ? In other word, that it won't use a cache of a content generated for a user won't be used for another one ?

X+

http://www.sydesy.com

Paul Forsyth

Wednesday 13 September 2006 8:41:46 am

Maybe the view cache of the full.tpl override is interfering? What if you ttl 0 that file?

Paul

Xavier Dutoit

Wednesday 13 September 2006 9:06:14 am

Hi Paul and thanks for the suggestion.

I'll try to change that. The problem is as I can't find a predictable way of having the two parts out of sync, I can only try to login/out with a different user until something happend. If it doesn't, it won't mean it won't happend later.

Anyway, the ttl=0 isn't going to be very good for the perf ;)

X+

P.S. Is there a way to debug the cache ? I would like to display informations about what is in the cache (file name?) and what isn't. How do you do that ?

http://www.sydesy.com

Xavier Dutoit

Friday 15 September 2006 11:17:32 pm

Hi,

Found one of the problems: the TTL of the cache isn't set, so that's two hours per default. After two hours, the cache isn't cleared, but the variable isn't calculated when the cache is recalculated.

I'll try to play with expiry=expiry ignore_content_expiry or subtree_expiry=subtree_expiry

That's going to be great fun to debug...

X+

http://www.sydesy.com

Paul Forsyth

Sunday 17 September 2006 8:29:17 am

You could ttl=0 the whole template but then cache-block everything within according to your needs with appropriate keys.

Not sure if your last comment suggests a bug or not.

Hope your having fun!

P

Xavier Dutoit

Sunday 17 September 2006 3:01:59 pm

Hi,

I don't think that's a bug, just hard to make it work.

Taking about you suggestion or ttling the content and using cache, I'm not sure they are any options to do reproduce the same result.

Eg: full.tpl

{set-block scope=root variable=cache_ttl}0{/set-block}
{cache-block
key=???
expiry=0
subtree_expiry=$node.url_alias}

1) I don't know what's the key to put to have the same one that the standard content.
It looks like it's somehow dependent on the user (eg an admin on the forum here and a regular user aren't going to have the same thing), but it isn't recalculated for every user (can be proven wrong, but I think that would explain the bug of the misterious edit button on the wrong posts in the forum on ez);.

2) The cache is going to be cleared on any item published under it, no matter how deep it is. The standard behaviour is to limit that to the node and its children (deep=1).

Am I wrong ? I never found any definitive descriptions on the rules of the content cache (what are the rules to decide if the cache is used or if it's recalculated) and it behaves differently when the template is compiled or isn't.

Has someone seen something like that ?

X+

http://www.sydesy.com