Problem with view cache

Author Message

Jerome Despatis

Wednesday 24 August 2011 2:33:47 am

Hello,

I have a website with, nearly in all pages, a region that gives some info on the current logged user.

But I get a problem of cache, for example I log on user1 => I see in this region the name of user 1, which is correct

Then I logout, and I log on user2 => but then I still see the name of user 1 in the region... I should see user 2!

If I clean the "Content View Cache", then all go to normal, and I see user 2 in the region

For now, in order to fix this problem, I've added in my site.ini:

[ContentSettings]
ViewCacheTweaks[global]=pr_user

In order to force the view cache per user, but I guess it will create a lot of new cache!

Any better way ?

Would be better indeed to let the default setting but tell to ez that this little region template depends of the user, possible ?

Carlos Revillo

Wednesday 24 August 2011 3:16:45 am

i would try to move the "per user" to pagelayout.tpl. i wouldn't  add cache to that per user part.

Jerome Despatis

Wednesday 24 August 2011 3:30:04 am

I don't think I can as the region I'm talking about is not in a cache-block in pagelayout (there yes I could add a new key to the cache-block), but it's in the content

hence some logic on the content cache

Or I'm wrong?

Carlos Revillo

Wednesday 24 August 2011 3:45:01 am

yes. what i mean if i would try to "redesign" the thing to not have a per user section inside of your full views or whatever that could be depending on viewcache.

ihmo, if the section is something to tell the user if its logged or not and things like that, i would that part ouside view cache and also outside every cache-block

as you say, you would need a new key (user_id) for those cache-block... but that would lead in lot of cache files on disk, specially if you have lot of users...

Carlos Revillo

Wednesday 24 August 2011 3:46:22 am

Other workaround could be using ajax for that part, but i don't really like it :)

Jerome Despatis

Wednesday 24 August 2011 3:52:55 am

As you say, it's a workaround :)

Any other option?

Daniel A. Øien

Wednesday 24 August 2011 6:16:22 am

You can use cache-blocks inside the view/override template with the user id as key. You'll end up with one cache-block for the information you want to display for each user, but at least it'll be a small block instead of an entire view cache per user.

Daniel A. Øien
Open Concept SA, Norway
Web: http://openconcept.no/
In English: http://openconcept.no/eng

Carlos Revillo

Wednesday 24 August 2011 7:04:38 am

"

You can use cache-blocks inside the view/override template with the user id as key. You'll end up with one cache-block for the information you want to display for each user, but at least it'll be a small block instead of an entire view cache per user.

"

well, but on the other side, for this work properly you will need to disable viewcache, right? or ttl for that specific template... imho there is no gain here...

Jerome Despatis

Wednesday 24 August 2011 8:05:52 am

Thanks Daniel, that's indeed what I've tried first, but it didn't work.

And as Carlos say, I guess it's because of the viewcache activated on my eZ

I try the ttl for that specific template, asap I find the good setting, (carlos if you have it, do not hesitate to paste it :p)

If it work, it would be good for me carlos, I would avoid the cache per user, and just a small part (my user region) with no cache

Jerome Despatis

Wednesday 24 August 2011 8:08:55 am

As I can read here:

http://doc.ez.no/eZ-Publish/Technical-manual/4.x/Reference/Template-functions/Variables/set-block

I can add in my region block the code:

<span class="line">{set-block scope=global variable=cache_ttl}0{/set-block}</span>

It would disable the cache for my region

But it would also disable the cache for the full page right ? (which I don't want)

There's a solution to deactive cache only for a little template that may be included by others (those others should be cached, but not the included template that contains my region)

Carlos Revillo

Wednesday 24 August 2011 8:21:22 am

Hi Jerome. I'm afraid there's no solution for that. is something i'll really like too. I started to work on that but after some nice talks with eZ Crew people, i realized there's no way to do it.

This kind of thing is possible with ezcomponents template engine, so maybe in the future we could have it on ez publish too.

In the meantime, best solution is do not cache that part, and for that you will need try to move it to pagelayout instead of your full view.

Jerome Despatis

Wednesday 24 August 2011 9:49:42 am

well site is offline for now, so I'll keep with the cache per user :)

But the fact also is I don't really see the difference between ViewCacheTweaks[global]=pr_user, and your proposal of putting my region into pagelayout

In both cases, I'll have cache per user, which is not optimal, but it's ok for now and let's wait for a better option...

Carlos Revillo

Wednesday 24 August 2011 10:15:08 am

well. i think there are some differences. i'll try to explain. suppose your full view template implies 1000 queries to your database. if you use cache per user, whenever new user enters, those 1000 queries will be executed again.

think of this if you have lot of users entering at the same time...

without it, you only do that once...

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.