=== modified file 'includes/cache.inc'
--- includes/cache.inc	2009-11-10 22:06:09 +0000
+++ includes/cache.inc	2009-12-01 12:42:45 +0000
@@ -303,14 +303,17 @@ class DrupalDatabaseCache implements Dru
   }
 
   function get($cid) {
+    $old_connection_key = Database::SetActiveConnection('cache');
     // Garbage collection necessary when enforcing a minimum cache lifetime.
     $this->garbageCollection($this->bin);
     $cache = db_query("SELECT data, created, headers, expire, serialized FROM {" . $this->bin . "} WHERE cid = :cid", array(':cid' => $cid))->fetchObject();
+    Database::SetActiveConnection($old_connection_key);
 
     return $this->prepareItem($cache);
   }
 
   function getMultiple(&$cids) {
+    $old_connection_key = Database::SetActiveConnection('cache');
     // Garbage collection necessary when enforcing a minimum cache lifetime.
     $this->garbageCollection($this->bin);
     $query = db_select($this->bin);
@@ -325,6 +328,7 @@ class DrupalDatabaseCache implements Dru
       }
     }
     $cids = array_diff($cids, array_keys($cache));
+    Database::SetActiveConnection($old_connection_key);
     return $cache;
   }
 
@@ -409,15 +413,18 @@ class DrupalDatabaseCache implements Dru
       $fields['serialized'] = 0;
     }
 
+    $old_connection_key = Database::SetActiveConnection('cache');
     db_merge($this->bin)
       ->key(array('cid' => $cid))
       ->fields($fields)
       ->execute();
+    Database::SetActiveConnection($old_connection_key);
   }
 
   function clear($cid = NULL, $wildcard = FALSE) {
     global $user;
 
+    $old_connection_key = Database::SetActiveConnection('cache');
     if (empty($cid)) {
       if (variable_get('cache_lifetime', 0)) {
         // We store the time in the current user's $user->cache variable which
@@ -475,15 +482,18 @@ class DrupalDatabaseCache implements Dru
           ->execute();
       }
     }
+    Database::SetActiveConnection($old_connection_key);
   }
 
   function isEmpty() {
+    $old_connection_key = Database::SetActiveConnection('cache');
     $this->garbageCollection();
     $query = db_select($this->bin);
     $query->addExpression('1');
     $result = $query->range(0, 1)
       ->execute()
       ->fetchField();
+    Database::SetActiveConnection($old_connection_key);
     return empty($result);
   }
 }

=== modified file 'includes/database/database.inc'
--- includes/database/database.inc	2009-11-19 04:00:47 +0000
+++ includes/database/database.inc	2009-12-01 12:38:43 +0000
@@ -1394,8 +1394,8 @@ abstract class Database {
     if (!empty(self::$databaseInfo[$key])) {
       $old_key = self::$activeKey;
       self::$activeKey = $key;
-      return $old_key;
     }
+    return $old_key;
   }
 
   /**

