Forums / Developer / Problem with view cache

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...

eZ debug

Timing: Jan 17 2025 20:52:08
Script start
Timing: Jan 17 2025 20:52:08
Module start 'content'
Timing: Jan 17 2025 20:52:09
Module end 'content'
Timing: Jan 17 2025 20:52:09
Script end

Main resources:

Total runtime0.9934 sec
Peak memory usage4,096.0000 KB
Database Queries227

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0069 597.0625180.8516
Module start 'content' 0.00690.8802 777.9141723.4766
Module end 'content' 0.88700.1062 1,501.3906344.6797
Script end 0.9933  1,846.0703 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00390.3914210.0002
Check MTime0.00150.1483210.0001
Mysql Total
Database connection0.00050.051310.0005
Mysqli_queries0.903490.94192270.0040
Looping result0.00180.18292250.0000
Template Total0.968497.520.4842
Template load0.00170.167420.0008
Template processing0.966797.315420.4834
Template load and register function0.00040.037410.0004
states
state_id_array0.00060.057210.0006
state_identifier_array0.00090.094320.0005
Override
Cache load0.00160.1640620.0000
Sytem overhead
Fetch class attribute can translate value0.00200.202540.0005
Fetch class attribute name0.00100.1049140.0001
XML
Image XML parsing0.00220.221640.0006
class_abstraction
Instantiating content class attribute0.00000.0021140.0000
General
dbfile0.00410.4154270.0002
String conversion0.00000.001030.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
13content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
17content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1content/datatype/view/ezxmltags/quote.tpldatatype/ezxmltext/quote.tplextension/ezwebin/design/ezwebin/override/templates/datatype/ezxmltext/quote.tplEdit templateOverride template
1content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 37
 Number of unique templates used: 9

Time used to render debug report: 0.0002 secs