Index: includes/cache.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/cache.inc,v
retrieving revision 1.27
diff -u -p -r1.27 cache.inc
--- includes/cache.inc	12 Oct 2008 04:30:05 -0000	1.27
+++ includes/cache.inc	12 Nov 2008 22:26:00 -0000
@@ -15,9 +15,53 @@
  * @return The cache or FALSE on failure.
  */
 function cache_get($cid, $table = 'cache') {
-  global $user;
-
   // Garbage collection necessary when enforcing a minimum cache lifetime
+  _cache_garbage_collection($table);
+  $cache = db_query("SELECT data, created, headers, expire, serialized FROM {" . $table . "} WHERE cid = :cid", array(':cid' => $cid))->fetchObject();
+  return _cache_prepare_item($cache);
+}
+
+/**
+ * Return data and cache misses from the persistent cache when given an array
+ * of cache IDs.
+ *
+ * @param $cids
+ *   An array of cache IDs for the data to retrieve.
+ * @param $table
+ *   The table $table to store the data in. Valid core values are
+ *   'cache_filter', 'cache_menu', 'cache_page', or 'cache' for
+ *   the default cache.
+ *
+ * @return
+ *   An array in the form array('cached' => $cache, 'misses' =>$cids), cached
+ *   items are indexed by cid.
+ */
+function cache_get_multiple($cids, $table = 'cache') {
+  // Garbage collection necessary when enforcing a minimum cache lifetime.
+  _cache_garbage_collection($table);
+  $query = db_select($table);
+  $query->fields($table, array('cid', 'data', 'created', 'headers', 'expire', 'serialized'));
+  $query->condition($table . '.cid', $cids, 'IN');
+  $result = $query->execute();
+  $cache = array();
+  foreach ($result as $item) {
+    $item = _cache_prepare_item($item);
+    if ($item) {
+      $cache[$item->cid] = $item;
+    }
+  }
+  $cids = array_diff_keys(array_flip($cids), $cache);
+  return array('cached' => $cached,  'misses' => $cids);
+}
+
+/**
+ * Garbage collection for cache_get() and cache_get_multiple().
+ *
+ * @param $table
+ *  The table being requested.
+ */
+function _cache_garbage_collection($table) {
+  global $user;
   $cache_flush = variable_get('cache_flush', 0);
   if ($cache_flush && ($cache_flush + variable_get('cache_lifetime', 0) <= REQUEST_TIME)) {
     // Reset the variable immediately to prevent a meltdown in heavy load situations.
@@ -28,8 +72,19 @@ function cache_get($cid, $table = 'cache
       ->condition('expire', $cache_flush, '<=')
       ->execute();
   }
+}
 
-  $cache = db_query("SELECT data, created, headers, expire, serialized FROM {" . $table . "} WHERE cid = :cid", array(':cid' => $cid))->fetchObject();
+
+/**
+ * Utility function for preparing a cached item.
+ *
+ * @param $cache
+ *   An item loaded from cache_get or cache_get_multiple
+ *
+ * @return
+ *   The item with data unserialized as appropriate.
+ */
+function _cache_prepare_item($cache) {
   if (isset($cache->data)) {
     // If the data is permanent or we're not enforcing a minimum cache lifetime
     // always return the cached data.
