Forums / Developer / custom caching from within an extension

custom caching from within an extension

Author Message

Matthew Carroll

Thursday 11 March 2010 10:28:26 am

I'm building an ez extension which uses some template operators to look up info on an external website. I don't have control over that site or direct access to the database, so it uses curl to scrape the info and xpaths to analyse.

There are three curl page fetches each time my extension's php is hit, one of which changes every time, the second and third of which change much less often, so could be cached. Is there any way to use ez's caching mechanisms from within my extension to cache the result from that second lookup somehow?

Any pointers to appropriate documentation or similar example to work from would be really appreciated.

Thanks
Matthew

http://carroll.org.uk

Gaetano Giunta

Thursday 11 March 2010 1:04:43 pm

- create a template fetch function that does the ws calls

- put cache blocks around those calls in the template

Principal Consultant International Business
Member of the Community Project Board

Matthew Carroll

Thursday 11 March 2010 2:09:52 pm

Thanks! That was the nudge I needed to see the problem from a new angle.

Currently it does all three external fetches within the one operator function, but if I extract some of the logic out to the ez template instead, and put the second and third lookups in a separate function, it will be more efficient overall.

I was trying to imagine taking the caching into the php of the extension, when what I need to do is bring a small portion of the extension logic out to the ez template. I just wasn't thinking about the problem the right way (isn't that always the challenge!)

http://carroll.org.uk

Matthew Carroll

Thursday 11 March 2010 7:48:41 pm

Unfortunately the approach I thought would work doesn't seem to.

I took out the second two external website lookups and put them into a template fetch function, but I need to be able to access the result of that fetch as a variable later on. If I do this:

{cache-block expiry=86400}
{def $mylist=fetch( 'mplookup', 'list', hash())}
{/cache-block}

...it doesn't work the second time, as the variable $mylist doesn't exist once that block is cached. Does that make sense? I want to cache the result of the fetch, but still be able to access the variable next time that template is used (with a different view parameter). Am I missing something obvious here?

Thanks
Matthew

http://carroll.org.uk

Gaetano Giunta

Friday 12 March 2010 12:29:13 am

No, it is the way cache-blocks work: the actual html is stored in the file on disk, no template-level variable.

Workarounds:

- move the display of the results within the cache-block (nb: cache-blocks can be nested)

- let the cache-block save data into a js variable and use it later down the page for display

Principal Consultant International Business
Member of the Community Project Board

eZ debug

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

Main resources:

Total runtime0.8273 sec
Peak memory usage4,096.0000 KB
Database Queries200

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0073 588.9453180.8281
Module start 'content' 0.00730.7113 769.7734573.8047
Module end 'content' 0.71860.1086 1,343.5781337.3828
Script end 0.8272  1,680.9609 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00380.4596210.0002
Check MTime0.00140.1696210.0001
Mysql Total
Database connection0.00130.153010.0013
Mysqli_queries0.747990.40482000.0037
Looping result0.00190.22861980.0000
Template Total0.793195.920.3966
Template load0.00190.228920.0009
Template processing0.791295.638320.3956
Template load and register function0.00010.012710.0001
states
state_id_array0.00140.169910.0014
state_identifier_array0.00160.187520.0008
Override
Cache load0.00170.2055340.0001
Sytem overhead
Fetch class attribute can translate value0.00150.183530.0005
Fetch class attribute name0.00120.140870.0002
XML
Image XML parsing0.00120.149730.0004
class_abstraction
Instantiating content class attribute0.00000.0028100.0000
General
dbfile0.00360.4398330.0001
String conversion0.00000.000730.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
5content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
5content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
9content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezxmltags/emphasize.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/emphasize.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: 25
 Number of unique templates used: 8

Time used to render debug report: 0.0002 secs