diff --git a/core/lib/Drupal/Core/Cache/DatabaseBackend.php b/core/lib/Drupal/Core/Cache/DatabaseBackend.php
index e90e2ad..105068b 100644
--- a/core/lib/Drupal/Core/Cache/DatabaseBackend.php
+++ b/core/lib/Drupal/Core/Cache/DatabaseBackend.php
@@ -7,6 +7,7 @@
 
 namespace Drupal\Core\Cache;
 
+use Drupal\Core\Database\Database;
 use Exception;
 
 /**
@@ -28,6 +29,11 @@ class DatabaseBackend implements CacheBackendInterface {
   protected static $tagCache = array();
 
   /**
+   * A database connection object.
+   */
+  protected $dbConnection;
+
+  /**
    * Implements Drupal\Core\Cache\CacheBackendInterface::__construct().
    */
   function __construct($bin) {
@@ -37,6 +43,22 @@ class DatabaseBackend implements CacheBackendInterface {
       $bin = 'cache_' . $bin;
     }
     $this->bin = $bin;
+    // Don't want to add this to the CacheBackendInterface, but also just
+    // calling Database::getConnection() feels wrong.
+    // @todo: not sure. Use the DIC?
+    $this->dbConnection = Database::getConnection();
+  }
+
+  /**
+   * Set the database connection for this cache object.
+   *
+   * @todo: this is only here to allow the database connection to be set
+   * outside of the constructor.
+   *
+   * @param Connection $dbConnection
+   */
+  public function setDbConnection(Connection $dbConnection) {
+    $this->dbConnection = $dbConnection;
   }
 
   /**
@@ -53,14 +75,14 @@ class DatabaseBackend implements CacheBackendInterface {
    */
   function getMultiple(&$cids) {
     try {
-      // When serving cached pages, the overhead of using db_select() was found
+      // When serving cached pages, the overhead of using ::select() was found
       // to add around 30% overhead to the request. Since $this->bin is a
-      // variable, this means the call to db_query() here uses a concatenated
+      // variable, this means the call to ::query() here uses a concatenated
       // string. This is highly discouraged under any other circumstances, and
       // is used here only due to the performance overhead we would incur
       // otherwise. When serving an uncached page, the overhead of using
-      // db_select() is a much smaller proportion of the request.
-      $result = db_query('SELECT cid, data, created, expire, serialized, tags, checksum FROM {' . db_escape_table($this->bin) . '} WHERE cid IN (:cids)', array(':cids' => $cids));
+      // ::select() is a much smaller proportion of the request.
+      $result = $this->dbConnection->query('SELECT cid, data, created, expire, serialized, tags, checksum FROM {' . $this->dbConnection->escapeTable($this->bin) . '} WHERE cid IN (:cids)', array(':cids' => $cids));
       $cache = array();
       foreach ($result as $item) {
         $item = $this->prepareItem($item);
@@ -135,7 +157,7 @@ class DatabaseBackend implements CacheBackendInterface {
     }
 
     try {
-      db_merge($this->bin)
+      $this->dbConnection->merge($this->bin)
         ->key(array('cid' => $cid))
         ->fields($fields)
         ->execute();
@@ -149,7 +171,7 @@ class DatabaseBackend implements CacheBackendInterface {
    * Implements Drupal\Core\Cache\CacheBackendInterface::delete().
    */
   function delete($cid) {
-    db_delete($this->bin)
+    $this->dbConnection->delete($this->bin)
       ->condition('cid', $cid)
       ->execute();
   }
@@ -160,7 +182,7 @@ class DatabaseBackend implements CacheBackendInterface {
   function deleteMultiple(array $cids) {
     // Delete in chunks when a large array is passed.
     do {
-      db_delete($this->bin)
+      $this->dbConnection->delete($this->bin)
         ->condition('cid', array_splice($cids, 0, 1000), 'IN')
         ->execute();
     }
@@ -171,8 +193,8 @@ class DatabaseBackend implements CacheBackendInterface {
    * Implements Drupal\Core\Cache\CacheBackendInterface::deletePrefix().
    */
   function deletePrefix($prefix) {
-    db_delete($this->bin)
-      ->condition('cid', db_like($prefix) . '%', 'LIKE')
+    $this->dbConnection->delete($this->bin)
+      ->condition('cid', $this->dbConnection->escapeLike($prefix) . '%', 'LIKE')
       ->execute();
   }
 
@@ -180,14 +202,14 @@ class DatabaseBackend implements CacheBackendInterface {
    * Implements Drupal\Core\Cache\CacheBackendInterface::flush().
    */
   function flush() {
-    db_truncate($this->bin)->execute();
+    $this->dbConnection->truncate($this->bin)->execute();
   }
 
   /**
    * Implements Drupal\Core\Cache\CacheBackendInterface::expire().
    */
   function expire() {
-    db_delete($this->bin)
+    $this->dbConnection->delete($this->bin)
       ->condition('expire', CACHE_PERMANENT, '<>')
       ->condition('expire', REQUEST_TIME, '<')
       ->execute();
@@ -250,7 +272,7 @@ class DatabaseBackend implements CacheBackendInterface {
   public function invalidateTags(array $tags) {
     foreach ($this->flattenTags($tags) as $tag) {
       unset(self::$tagCache[$tag]);
-      db_merge('cache_tags')
+      $this->dbConnection->merge('cache_tags')
         ->key(array('tag' => $tag))
         ->fields(array('invalidations' => 1))
         ->expression('invalidations', 'invalidations + 1')
@@ -280,9 +302,14 @@ class DatabaseBackend implements CacheBackendInterface {
       }
    }
     if ($query_tags) {
-      if ($db_tags = db_query('SELECT tag, invalidations FROM {cache_tags} WHERE tag IN (:tags)', array(':tags' => $query_tags))->fetchAllKeyed()) {
-        self::$tagCache = array_merge(self::$tagCache, $db_tags);
-        $checksum += array_sum($db_tags);
+      try {
+        if ($db_tags = $this->dbConnection->query('SELECT tag, invalidations FROM {cache_tags} WHERE tag IN (:tags)', array(':tags' => $query_tags))->fetchAllKeyed()) {
+          self::$tagCache = array_merge(self::$tagCache, $db_tags);
+          $checksum += array_sum($db_tags);
+        }
+      }
+      catch (Exception $e) {
+        // The database may not be available, so we'll ignore cache_set requests.
       }
     }
     return $checksum;
@@ -293,7 +320,7 @@ class DatabaseBackend implements CacheBackendInterface {
    */
   function isEmpty() {
     $this->garbageCollection();
-    $query = db_select($this->bin);
+    $query = $this->dbConnection->select($this->bin);
     $query->addExpression('1');
     $result = $query->range(0, 1)
       ->execute()
