Internal fetch cache/reuse per request?

Author Message

Piotrek Karaś

Sunday 03 February 2008 3:51:56 am

Are API fetches (especially all the ones wrapped around persistent layer) cached and reused somehow within a single request? When carrying out some PHP tasks that require fetching data, I always wonder if I should implement my own caching mechanisms.

<b>Example:</b> Let's say, we have an array of 100 objects with user ID references (7 different users). I want to fetch user object for each of the 100 objects. I could simply walk the array and fetch user object each time, which would make 100 times, but in fact, only 7 user fetches are actually necessary. Now, does eZ take care of such recurring fetches? Should I implement my own cache (which is quite easy) or would that be unnecessary work?

<b>Code example:</b>

$userObjectArray = array();
foreach( $objectList as $object )
{
  $userID = $object->ID;
  if( !isset( $userObjectArray[$userID] ) )
  {
    $userObjectArray[$userID] = eZContentObject::fetch( $userID );
  }
  ...
}

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

André R.

Sunday 03 February 2008 4:33:12 am

Objects, classes, sections, class attributes and I also think user object is cached.
They are cached with global variables in the different sections of the kernel.

The core team did test out putting the cache code in persistant object during 3.9 development, but it had too many regressions.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Piotrek Karaś

Sunday 03 February 2008 4:45:06 am

Thanks a lot, André!
Now I know where to look and in which cases. Naturally, number of SQL queries can be of much help.
Greets,
Piotrek

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

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

eZ debug

Timing: Jan 18 2025 19:10:26
Script start
Timing: Jan 18 2025 19:10:26
Module start 'layout'
Timing: Jan 18 2025 19:10:26
Module start 'content'
Timing: Jan 18 2025 19:10:27
Module end 'content'
Timing: Jan 18 2025 19:10:27
Script end

Main resources:

Total runtime1.0043 sec
Peak memory usage4,096.0000 KB
Database Queries57

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0063 588.0313152.6406
Module start 'layout' 0.00640.0031 740.671939.4609
Module start 'content' 0.00940.9932 780.1328549.0391
Module end 'content' 1.00260.0017 1,329.171912.1563
Script end 1.0043  1,341.3281 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00370.3714160.0002
Check MTime0.00170.1740160.0001
Mysql Total
Database connection0.00100.104210.0010
Mysqli_queries0.943893.9762570.0166
Looping result0.00060.0586550.0000
Template Total0.964696.020.4823
Template load0.00280.281920.0014
Template processing0.961795.759620.4809
Template load and register function0.00010.009910.0001
states
state_id_array0.00200.197310.0020
state_identifier_array0.00190.188920.0009
Override
Cache load0.00250.2449190.0001
Sytem overhead
Fetch class attribute can translate value0.00110.108920.0005
Fetch class attribute name0.00380.377150.0008
XML
Image XML parsing0.00100.098320.0005
class_abstraction
Instantiating content class attribute0.00000.001260.0000
General
dbfile0.00100.0949240.0000
String conversion0.00000.000740.0000
Note: percentages do not add up to 100% because some accumulators overlap

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/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
3content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 14
 Number of unique templates used: 7

Time used to render debug report: 0.0003 secs