diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-06-28 01:00:42 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-06-28 01:00:42 +0000 |
commit | 6c9436abbf5df740539215354b2eaa1b6893d2cf (patch) | |
tree | 0a1360252185b3f2d2d5d2535d1c579d3e1acc77 /modules/field/field.attach.inc | |
parent | 1d07289b039dee17fc17762635ce5872243be9b3 (diff) | |
download | brdo-6c9436abbf5df740539215354b2eaa1b6893d2cf.tar.gz brdo-6c9436abbf5df740539215354b2eaa1b6893d2cf.tar.bz2 |
#333171 by catch: Provide cache_get_multiple() and allow clearing of multiple cache IDs at once (with tests).
Diffstat (limited to 'modules/field/field.attach.inc')
-rw-r--r-- | modules/field/field.attach.inc | 34 |
1 files changed, 21 insertions, 13 deletions
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() |