#338221 by Damien Tournoud: cache and variable requests should always use the default database connection.

From: Damien Tournoud <damien@tournoud.net>


---

 includes/bootstrap.inc |    4 ++--
 includes/cache.inc     |   16 ++++++++--------
 2 files changed, 10 insertions(+), 10 deletions(-)


diff --git includes/bootstrap.inc includes/bootstrap.inc
index 8090f19..4d48527 100644
--- includes/bootstrap.inc
+++ includes/bootstrap.inc
@@ -626,7 +626,7 @@ function variable_get($name, $default) {
 function variable_set($name, $value) {
   global $conf;
 
-  db_merge('variable')->key(array('name' => $name))->fields(array('value' => serialize($value)))->execute();
+  Database::getConnection('default')->merge('variable')->key(array('name' => $name))->fields(array('value' => serialize($value)))->execute();
 
   cache_clear_all('variables', 'cache');
 
@@ -642,7 +642,7 @@ function variable_set($name, $value) {
 function variable_del($name) {
   global $conf;
 
-  db_delete('variable')
+  Database::getConnection('default')->delete('variable')
     ->condition('name', $name)
     ->execute();
   cache_clear_all('variables', 'cache');
diff --git includes/cache.inc includes/cache.inc
index 108bd2a..cee72f8 100644
--- includes/cache.inc
+++ includes/cache.inc
@@ -23,13 +23,13 @@ function cache_get($cid, $table = 'cache') {
     // 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)
+    Database::getConnection('default')->delete($table)
       ->condition('expire', CACHE_PERMANENT, '<>')
       ->condition('expire', $cache_flush, '<=')
       ->execute();
   }
 
-  $cache = db_query("SELECT data, created, headers, expire, serialized FROM {" . $table . "} WHERE cid = :cid", array(':cid' => $cid))->fetchObject();
+  $cache = Database::getConnection('default')->query("SELECT data, created, headers, expire, serialized FROM {" . $table . "} WHERE cid = :cid", array(':cid' => $cid))->fetchObject();
   if (isset($cache->data)) {
     // If the data is permanent or we're not enforcing a minimum cache lifetime
     // always return the cached data.
@@ -120,7 +120,7 @@ function cache_set($cid, $data, $table = 'cache', $expire = CACHE_PERMANENT, $he
     $fields['serialized'] = 0;
   }
 
-  db_merge($table)
+  Database::getConnection('default')->merge($table)
     ->key(array('cid' => $cid))
     ->fields($fields)
     ->execute();
@@ -171,7 +171,7 @@ function cache_clear_all($cid = NULL, $table = NULL, $wildcard = FALSE) {
       elseif (REQUEST_TIME > ($cache_flush + variable_get('cache_lifetime', 0))) {
         // Clear the cache for everyone, cache_flush_delay seconds have
         // passed since the first request to clear the cache.
-        db_delete($table)
+        Database::getConnection('default')->delete($table)
           ->condition('expire', CACHE_PERMANENT, '<>')
           ->condition('expire', REQUEST_TIME, '<')
           ->execute();
@@ -180,7 +180,7 @@ function cache_clear_all($cid = NULL, $table = NULL, $wildcard = FALSE) {
     }
     else {
       // No minimum cache lifetime, flush all temporary cache entries now.
-      db_delete($table)
+      Database::getConnection('default')->delete($table)
         ->condition('expire', CACHE_PERMANENT, '<>')
         ->condition('expire', REQUEST_TIME, '<')
         ->execute();
@@ -189,16 +189,16 @@ function cache_clear_all($cid = NULL, $table = NULL, $wildcard = FALSE) {
   else {
     if ($wildcard) {
       if ($cid == '*') {
-        db_delete($table)->execute();
+        Database::getConnection('default')->delete($table)->execute();
       }
       else {
-        db_delete($table)
+        Database::getConnection('default')->delete($table)
           ->condition('cid', $cid . '%', 'LIKE')
           ->execute();
       }
     }
     else {
-      db_delete($table)
+      Database::getConnection('default')->delete($table)
         ->condition('cid', $cid)
         ->execute();
     }
