Forums / Developer / cache-block strikes again

cache-block strikes again

Author Message

Pablo Pernot

Thursday 26 March 2009 10:38:38 am

Hi all,

Need help about cache-block within menu and submenu.

here is my code :

The cache-block works well with $mainMenu, $menu but it won't work with the highlight of the submenu $subMenu, $sub and $sub.is_selected.

Is there any good practice and clue about managing menu and submenu with cache-block ?

thanks

an extract from the code below :

<div id="header">
    <ul id="menu-niv-1">
    <!--cdlBloc ordre="8"-->
    {def $secteur=fetch('content','node',hash('node_id', ezini( 'NodeSettings', 'VotreSecteurActivite', 'config.ini.append.php')))}
    {def $mainMenu=treemenu( $module_result.path, ,
                                        array('actualite','offre','groupe','contact'), 0, 1 )}
   
    {cache-block keys=array($mainMenu,$menu,$secteur)}
    {foreach $mainMenu as $menu}
        {if $menu.is_selected}
        	{if eq($menu.node.class_identifier,'actualite')}
            	<li id="actualite"><a href={$menu.url_alias|ezurl} id="actif" accesskey="2"><span>{$menu.text|upfirst}</span></a>
                    {if eq($menu.has_children, '1')}
                    	<ul id="menu-niv-2">
                        {def $subMenu=treemenu( $module_result.path, ,
                                        array('master_press','master_evenement','master_communique','gallery'), 1, 1 )}
                                        
                                        
                            {cache-block keys=array($subMenu)}            
                        	{foreach $subMenu as $sub}
                            	{cache-block keys=array($sub.node.class_identifier)}
                                {if $sub.is_selected}
                                	{if eq($sub.node.class_identifier,'master_communique')}
                                    	<li id="communiques"><a href={$sub.url_alias|ezurl} id="on"><span>{$sub.text|upfirst}</span></a></li>
                                    {/if}
                                    {if eq($sub.node.class_identifier,'master_evenement')}
                                    	<li id="evenements"><a href={$sub.url_alias|ezurl} id="on"><span>{$sub.text|upfirst}</span></a></li>
                                    {/if}
                                    {if eq($sub.node.class_identifier,'master_press')}
                                    	<li id="revue-presse"><a href={$sub.url_alias|ezurl} id="on"><span>{$sub.text|upfirst}</span></a></li>
                                    {/if}
                                    {if eq($sub.node.class_identifier,'gallery')}
                                    	<li id="phototheque"><a href={$sub.url_alias|ezurl} id="on"><span>{$sub.text|upfirst}</span></a></li>
                                    {/if}
                                {else}
                                	{if eq($sub.node.class_identifier,'master_communique')}
                                    	<li id="communiques"><a href={$sub.url_alias|ezurl}><span>{$sub.text|upfirst}</span></a></li>
                                    {/if}
                                    {if eq($sub.node.class_identifier,'master_evenement')}
                                    	<li id="evenements"><a href={$sub.url_alias|ezurl}><span>{$sub.text|upfirst}</span></a></li>
                                    {/if}
                                    {if eq($sub.node.class_identifier,'master_press')}
                                    	<li id="revue-presse"><a href={$sub.url_alias|ezurl}><span>{$sub.text|upfirst}</span></a></li>
                                    {/if}
                                    {if eq($sub.node.class_identifier,'gallery')}
                                    	<li id="phototheque"><a href={$sub.url_alias|ezurl}><span>{$sub.text|upfirst}</span></a></li>
                                    {/if}
                                {/if}
                                {/cache-block}
                            {/foreach}
                        	{/cache-block}
                        </ul>
                    {/if}
                </li>
			{/if}

[.....]

Pablo Pernot
http://www.smartview.fr
http://www.areyouagile.com

Piotrek Karaś

Thursday 26 March 2009 9:13:19 pm

Pablo,

When you think about it, it's only obvious it won't work. I don't know how your website works, but I assume you have a flat main menu and a multi-level contextual submenu. Let's say there are 10 main categories for main menu, and each category contains 20 pages with links for each page. This gives a total of 200 pages, right?

Now, you've placed submenu cache block, with its keys, within the main menu cache block. Main menu has 10 combinations, submenu has 200 combinations. When do you expect the submenu to have a chance to refresh?

{* This won't work! *}
{cache-block keys=$mainmenu_keys}
    {MENU HERE}
    {SUBMENU HERE}
{/cache}

If you need to have both menus packed into one cache-block, you have set expiry keys combination that would serve the smalles possible entity, in this case a submenu item:

{* This should work! *}
{cache-block keys=$submenu_keys}
    {MENU HERE}
    {SUBMENU HERE}
{/cache}

We hardly ever can do without two separate cacheblocks, one for main menu, one for submenu:

{* This works! *}
{cache-block keys=$mainmenu_keys}
    {MENU HERE}
{/cache}
{cache-block keys=$submenu_keys}
    {SUBMENU HERE}
{/cache}

This approach gives you the possibility to further optimize your menus separately! For $mainmenu_keys you only need an array of 10 node combinations + one combination for all other tools (login, edit, etc.).

For many websites it is not necessary to have all the nodes in the menu. Usually, you place navigation/folder-like items to act as a menu, while multiple articles are never shown there, only in the breadcrumb navigation.

Imagine this scenario: your website has:
- 10 main menu categories
- 200 submenu categories
- 10000 articles

If you base your menu cache on the entire path, you will end up with at least 10210 cache files stored in your cache directory for a menu that only has 200 combinations! You're most likely to be forced to clear your cache-blocks before it ever gets completely generated ;)

What you can do is calculate proper cache-block exipry keys based on depth, class, etc. So that they really reflect what's going on in your menu.

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

Pablo Pernot

Thursday 26 March 2009 11:31:16 pm

Thanks for your feedback.

What about nested cache-block ?


{cache-block keys=$mainmenu_keys}
   {MENU HERE}
     {cache-block keys=$submenu_keys}
        {SUBMENU HERE}
     {/cache}
     {cache-block keys=$submenu_keys}
        {SUBMENU HERE}
     {/cache}
{/cache}

Is that different than your proposition ?

{cache-block keys=$mainmenu_keys}
   {MENU HERE}
{/cache}
{cache-block keys=$submenu_keys}
   {SUBMENU HERE}
{/cache}

Pablo Pernot
http://www.smartview.fr
http://www.areyouagile.com

Piotrek Karaś

Friday 27 March 2009 12:37:50 am

What about nested cache-block ?

Nested cache-blocks work, but you can't include detailed rules in general rules because detailed rules will be cached within general rules. This would make sense:

{cache-block $submenu_keys}
    {cache-block $mainmenu_keys}
        MAINMENU
    {/cache-block}
    SUBMENU
{/cache-block}

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

eZ debug

Timing: Jan 18 2025 11:21:37
Script start
Timing: Jan 18 2025 11:21:37
Module start 'content'
Timing: Jan 18 2025 11:21:37
Module end 'content'
Timing: Jan 18 2025 11:21:38
Script end

Main resources:

Total runtime0.1657 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0079 587.7109180.8359
Module start 'content' 0.00790.0055 768.5469105.9922
Module end 'content' 0.01340.1522 874.5391541.2734
Script end 0.1656  1,415.8125 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00352.1077200.0002
Check MTime0.00140.8294200.0001
Mysql Total
Database connection0.00150.925310.0015
Mysqli_queries0.117370.78421410.0008
Looping result0.00191.12201390.0000
Template Total0.151891.610.1518
Template load0.00090.537210.0009
Template processing0.150991.104010.1509
Override
Cache load0.00060.384510.0006
Sytem overhead
Fetch class attribute can translate value0.00080.486510.0008
XML
Image XML parsing0.00020.134010.0002
General
dbfile0.00261.5587200.0001
String conversion0.00000.005530.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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0002 secs