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.