From 6c9436abbf5df740539215354b2eaa1b6893d2cf Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Sun, 28 Jun 2009 01:00:42 +0000 Subject: #333171 by catch: Provide cache_get_multiple() and allow clearing of multiple cache IDs at once (with tests). --- modules/field/field.attach.inc | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'modules/field/field.attach.inc') diff --git a/modules/field/field.attach.inc b/modules/field/field.attach.inc index 42984beba..6c68c57a3 100644 --- a/modules/field/field.attach.inc +++ b/modules/field/field.attach.inc @@ -399,28 +399,36 @@ function field_attach_load($obj_type, $objects, $age = FIELD_LOAD_CURRENT) { $info = field_info_fieldable_types($obj_type); $cacheable = $load_current && $info['cacheable']; - $queried_objects = array(); + if (empty($objects)) { + return; + } + + // Assume all objects will need to be queried. Objects found in the cache + // will be removed from the list. + $queried_objects = $objects; - // Fetch avaliable objects from cache. + // Fetch available objects from cache, if applicable. if ($cacheable) { + // Build the list of cache entries to retrieve. + $cids = array(); + foreach ($objects as $id => $object) { + $cids[] = "field:$obj_type:$id"; + } + $cache = cache_get_multiple($cids, 'cache_field'); + // Put the cached field values back into the objects and remove them from + // the list of objects to query. foreach ($objects as $id => $object) { $cid = "field:$obj_type:$id"; - if ($cached = cache_get($cid, 'cache_field')) { - foreach ($cached->data as $key => $value) { - $object->$key = $value; + if (isset($cache[$cid])) { + unset($queried_objects[$id]); + foreach ($cache[$cid]->data as $field_name => $values) { + $object->$field_name = $values; } } - else { - $queried_objects[$id] = $objects[$id]; - } } } - else { - $queried_objects = $objects; - } - - // Fetch other objects from the database. + // Fetch other objects from their storage location. if ($queried_objects) { // The invoke order is: // - hook_field_attach_pre_load() -- cgit v1.2.3