Forums / Developer / {cache-block} implementation again

{cache-block} implementation again

Author Message

Alexei Pechekhonov

Thursday 05 June 2003 7:05:50 am

{cache-block} looks like very helpful feature, but...
i can't belive in restrictions of using it.I i can use cache-block for includes without errors only:
{cache-block keys=array('search_subscribe',$uri_string)}
{include uri="design/my_site/templates/search_subscribe.tpl"}
{/cache-block}

But when i try make cache for query-arrays - it looks like working and quicker, but i have errors from debugger output:

1. i try to use before {let} statemant, it works, but ....
{cache-block keys=array($current_root, $news_list, $article_list, $event_list, $product_list, $static_list, $DesignKeys:used.node) expiry=28000}
{let
current_root=fetch(content,node,hash(node_id,55))
news_list=fetch(content,tree,hash(parent_node_id,19,limit,5,sort_by,array(published,false()),class_filter_type,include,class_filter_array,array(2,7)))
article_list=fetch(content,tree,hash(parent_node_id,20,limit,5,depth,2,sort_by,array(published,false()),class_filter_type,include,class_filter_array,array(2)))
event_list=fetch(content,tree,hash(parent_node_id,21,limit,5,sort_by,array(published,false()),class_filter_type,include,class_filter_array,array(2,8)))
product_list=fetch(content,tree,hash(parent_node_id,22,limit,5,sort_by,array(published,false()),class_filter_type,include,class_filter_array,array(2,21)))
static_list=fetch(content,list,hash(parent_node_id,55,limit,5,sort_by,$current_root.sort_array ))

}
.... some_page_code....
{/let}
{/cache-block}

debugger says:
Error: eZTemplate
Unknown template variable 'current_root' in namespace ''
Error: eZTemplate
Unknown template variable 'news_list' in namespace ''
Error: eZTemplate
Unknown template variable 'article_list' in namespace ''
Error: eZTemplate
Unknown template variable 'event_list' in namespace ''
Error: eZTemplate
Unknown template variable 'product_list' in namespace ''
Error: eZTemplate
Unknown template variable 'static_list' in namespace ''

because i use the variables before I set them.
Right, but how should i use cache-block for caching queries?
{let $current_root $news_list $article_list $event_list $product_list $static_list}
then
{set current_root = fetch(content,node,hash(node_id,55))}
{set news_list = fetch(content,tree,hash(parent_node_id,19,limit,5,sort_by,array(published,false()),class_filter_type,include,class_filter_array,array(2,7))) }
... etc
Is that? But in this case {set ...} doesn't want to work, because i have 3 namespaces '', 'First' and 'First:Second' and set-construction, say, :
{set article_list=fetch(content, list, hash(parent_node_id, $First:item.node_id, limit, 10, sort_by, $First:item.sort_array, class_filter_type, include, class_filter_array, array(2,13))) }
doesn't work. :(
Q: how should i use cache-block for caching queries?
Did somebody play around? Please ideas...

Bård Farstad

Thursday 05 June 2003 7:16:35 am

What you need to do is to figure out what makes the current block unique. E.g. if you've caching a menue which is the same inside every section you need to make the cache block unique pr section. The uniqueness is decided by the keys of the cache block.

If you have something which is unique pr page ( e.g. the path code ) you could use the request url to make the cache block unique.

Cache blocks will automatically expire when content is published and you can set a timeout.

--bård

Documentation: http://ez.no/doc

Alexei Pechekhonov

Thursday 05 June 2003 9:25:44 am

Thank you, Bard. Now i'm feeling myself more confidence :)
Couldn't you, please, demonstrate your ideas on my example?
Every section on my site has a few lists: menu, line-view, midle-view etc ...
e.g.
loop=list1,
loop=list2,
loop=list3 <--- + some internal loop4
Right? In let/default area i define 3 of them, then i use {set}, but it depends on section, so i need, like you've suggested, to use path/url var ( say $DesignKeys:used.node)for uniquness then cache-block:
{let list1 list2 list3 }
{cache-block keys=array($list1, $list2, $list3, $DesignKeys:used.node}

{set list1=fetch(content,list,hash(parent_node_id, $DesignKeys:used.node ...)}
{set list2=fetch(content,list,hash(parent_node_id, $DesignKeys:used.node ....)}
{set list3=fetch(content,list,hash( parent_node_id, $DesignKeys:used.node ....)}

some_funny_code ...
{section loop=list1 show=....} show_zone1 {/section}
{section loop=list2 show=....} show_zone2 {/section}
{section loop=list3 show=....} show_zone3 ...internal_loop4... {/section}
. . . . . . . . . . . . . . . . . . . . . .
{/cache-block}
{/let}

Yes, the "structure" of lists is the same, but parent_node_id is various from section to section.
Please correct me or share, please, another suitable point of view.

eZ debug

Timing: Jan 18 2025 10:24:18
Script start
Timing: Jan 18 2025 10:24:18
Module start 'content'
Timing: Jan 18 2025 10:24:19
Module end 'content'
Timing: Jan 18 2025 10:24:19
Script end

Main resources:

Total runtime1.2677 sec
Peak memory usage4,096.0000 KB
Database Queries194

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0093 587.7188180.8281
Module start 'content' 0.00931.0785 768.5469562.0859
Module end 'content' 1.08780.1798 1,330.6328336.7422
Script end 1.2676  1,667.3750 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00480.3798210.0002
Check MTime0.00160.1301210.0001
Mysql Total
Database connection0.00090.070010.0009
Mysqli_queries1.176192.77121940.0061
Looping result0.00220.17161920.0000
Template Total1.233097.320.6165
Template load0.00170.130620.0008
Template processing1.231497.135320.6157
Template load and register function0.00020.014610.0002
states
state_id_array0.00130.100410.0013
state_identifier_array0.00170.131420.0008
Override
Cache load0.00150.1198770.0000
Sytem overhead
Fetch class attribute can translate value0.00150.114930.0005
Fetch class attribute name0.00170.134340.0004
XML
Image XML parsing0.00100.075730.0003
class_abstraction
Instantiating content class attribute0.00000.000740.0000
General
dbfile0.00460.3663280.0002
String conversion0.00000.000630.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
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
8content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
9content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 23
 Number of unique templates used: 6

Time used to render debug report: 0.0002 secs