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 00:04:10 -0000
@@ -30,6 +30,63 @@ function cache_get($cid, $table = 'cache
   }
 
   $cache = db_query("SELECT data, created, headers, expire, serialized FROM {" . $table . "} WHERE cid = :cid", array(':cid' => $cid))->fetchObject();
+
+  return _cache_prepare_item($cache);
+}
+
+/**
+ * Return an array of data 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 of cached items indexed by cid.
+ */
+function cache_get_multiple($cids, $table = 'cache') {
+  global $user;
+
+  // Garbage collection necessary when enforcing a minimum cache lifetime
+  $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.
+    variable_set('cache_flush', 0);
+    // Time to flush old cache data
+    db_delete($table)
+      ->condition('expire', CACHE_PERMANENT, '<>')
+      ->condition('expire', $cache_flush, '<=')
+      ->execute();
+  }
+
+  $query = db_select($table);
+  $query->fields($table, array('cid', 'data', 'created', 'headers', 'expire', 'serialized');
+  $query->condition($table . '.cid', $cids, 'IN');
+  $cache = $query->execute()->fetchAllAssoc('cid');
+
+  foreach ($cache as $item) {
+    $item = _cache_prepare_item($item);
+    if (!$item) {
+      unset($item->cid);
+    }
+  }
+  return $cache;
+}
+
+/**
+ * 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.
@@ -56,6 +113,7 @@ function cache_get($cid, $table = 'cache
     }
     return $cache;
   }
+
   return FALSE;
 }
 
