Index: includes/cache.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/cache.inc,v
retrieving revision 1.48
diff -u -p -r1.48 cache.inc
--- includes/cache.inc	18 May 2010 18:26:30 -0000	1.48
+++ includes/cache.inc	27 Sep 2010 22:12:13 -0000
@@ -306,10 +306,15 @@ class DrupalDatabaseCache implements Dru
 
   function get($cid) {
     try {
+      $static_cache = &drupal_static("cache_{$this->bin}");
+      if (isset($static_cache[$cid])) {
+        return $static_cache[$cid];
+      }
       // Garbage collection necessary when enforcing a minimum cache lifetime.
       $this->garbageCollection($this->bin);
       $cache = db_query("SELECT data, created, expire, serialized FROM {" . $this->bin . "} WHERE cid = :cid", array(':cid' => $cid))->fetchObject();
-      return $this->prepareItem($cache);
+      $static_cache[$cid] = $this->prepareItem($cache);
+      return $static_cache[$cid];
     }
     catch (Exception $e) {
       // If the database is never going to be available, cache requests should
@@ -320,17 +325,23 @@ class DrupalDatabaseCache implements Dru
 
   function getMultiple(&$cids) {
     try {
+      $static_cache = &drupal_static("cache_{$this->bin}");
+      $cache = array();
+      foreach ($cids as $key => $cid) {
+        if (isset($static_cache[$cid])) {
+          $cache[$cid] = $static_cache[$cid];
+        }
+      }
       // Garbage collection necessary when enforcing a minimum cache lifetime.
       $this->garbageCollection($this->bin);
       $query = db_select($this->bin);
       $query->fields($this->bin, array('cid', 'data', 'created', 'expire', 'serialized'));
       $query->condition($this->bin . '.cid', $cids, 'IN');
-      $result = $query->execute();
-      $cache = array();
-      foreach ($result as $item) {
+      foreach ($query->execute() as $item) {
         $item = $this->prepareItem($item);
         if ($item) {
           $cache[$item->cid] = $item;
+          $static_cache[$item->cid] = $item;
         }
       }
       $cids = array_diff($cids, array_keys($cache));
@@ -430,6 +441,8 @@ class DrupalDatabaseCache implements Dru
   function clear($cid = NULL, $wildcard = FALSE) {
     global $user;
 
+    $static_cache = &drupal_static("cache_{$this->bin}");
+
     if (empty($cid)) {
       if (variable_get('cache_lifetime', 0)) {
         // We store the time in the current user's $user->cache variable which
@@ -446,6 +459,7 @@ class DrupalDatabaseCache implements Dru
         elseif (REQUEST_TIME > ($cache_flush + variable_get('cache_lifetime', 0))) {
           // Clear the cache for everyone, cache_lifetime seconds have
           // passed since the first request to clear the cache.
+          drupal_static_reset("cache_{$this->bin}");
           db_delete($this->bin)
             ->condition('expire', CACHE_PERMANENT, '<>')
             ->condition('expire', REQUEST_TIME, '<')
@@ -455,6 +469,7 @@ class DrupalDatabaseCache implements Dru
       }
       else {
         // No minimum cache lifetime, flush all temporary cache entries now.
+        drupal_static_reset("cache_{$this->bin}");
         db_delete($this->bin)
           ->condition('expire', CACHE_PERMANENT, '<>')
           ->condition('expire', REQUEST_TIME, '<')
@@ -463,6 +478,8 @@ class DrupalDatabaseCache implements Dru
     }
     else {
       if ($wildcard) {
+        // @todo Or use preg_grep() ?
+        drupal_static_reset("cache_{$this->bin}");
         if ($cid == '*') {
           db_truncate($this->bin)->execute();
         }
@@ -473,6 +490,9 @@ class DrupalDatabaseCache implements Dru
         }
       }
       elseif (is_array($cid)) {
+        foreach ($cid as $key) {
+          unset($static_cache[$key]);
+        }
         // Delete in chunks when a large array is passed.
         do {
           db_delete($this->bin)
@@ -482,6 +502,7 @@ class DrupalDatabaseCache implements Dru
         while (count($cid));
       }
       else {
+        unset($static_cache[$cid]);
         db_delete($this->bin)
           ->condition('cid', $cid)
           ->execute();
