diff --git a/core/lib/Drupal/Component/PhpStorage/CoordinatedMTimeProtectedFileStorage.php b/core/lib/Drupal/Component/PhpStorage/CoordinatedMTimeProtectedFileStorage.php
index f13c1ca..e4249ee 100644
--- a/core/lib/Drupal/Component/PhpStorage/CoordinatedMTimeProtectedFileStorage.php
+++ b/core/lib/Drupal/Component/PhpStorage/CoordinatedMTimeProtectedFileStorage.php
@@ -30,24 +30,14 @@
 class CoordinatedMTimeProtectedFileStorage extends MTimeProtectedFileStorage {
 
   /**
-   * The database query to use to fetch storage counter.
+   * A custom callable to use to fetch the counter.
    */
-  protected $dbQueryFetch;
+  protected $fetchCallable;
 
   /**
-   * The database query to use to update storage counter.
+   * A custom callable to use to increment the counter.
    */
-  protected $dbQueryUpdate;
-
-  /**
-   * The database query to used to initialize storage counter.
-   */
-  protected $dbQueryInit;
-
-  /**
-   * The database target to use for the storage counter.
-   */
-  protected $dbTarget;
+  protected $incrementCallable;
 
   /**
    * Constructs this CoordinatedMTimeProtectedFastFileStorage object.
@@ -56,45 +46,64 @@ class CoordinatedMTimeProtectedFileStorage extends MTimeProtectedFileStorage {
    */
   public function __construct(array $configuration) {
     parent::__construct($configuration);
-    $this->initializeDbConfiguration($configuration);
+
+    if (!empty($configuration['fetch_callable']) && is_callable($configuration['fetch_callable'])) {
+      $this->fetchCallable = $configuration['fetch_callable'];
+    }
+    if (!empty($configuration['increment_callable']) && is_callable($configuration['increment_callable'])) {
+      $this->incrementCallable = $configuration['increment_callable'];
+    }
   }
 
   /**
-   * Initialize database settings for fetching the shared counter.
+   * Fetch the counter for the service container path.
    *
-   * @param array $configuration
+   * @param int
+   *   The current counter to be used in the service container path.
    */
-  protected function initializeDbConfiguration(array $configuration) {
-    $this->dbQueryInit = "INSERT INTO {key_value} (collection, name, value)
-                          VALUES ('coordinated_mtime_storage_counter', 'service_container_counter', 0)";
-    if (!empty($configuration['db_query_init'])) {
-      $this->dbQueryInit = $configuration['db_query_init'];
+  protected function fetchCounter() {
+    if ($this->fetchCallable) {
+      $callable = $this->fetchCallable;
+      return $callable();
     }
 
-    $this->dbQueryFetch = "SELECT value
-                           FROM {key_value}
-                           WHERE collection = 'coordinated_mtime_storage_counter'
-                           AND name = 'service_container_counter'";
-    if (!empty($configuration['db_query_fetch'])) {
-      $this->dbQueryFetch = $configuration['db_query_fetch'];
-    }
+    $sql = "SELECT value
+            FROM {key_value}
+            WHERE collection = 'coordinated_mtime_storage_counter'
+            AND name = 'service_container_counter'";
+    return Database::getConnection()
+      ->query($sql)
+      ->fetchColumn();
+  }
 
-    $this->dbQueryUpdate = "UPDATE {key_value}
-                            SET value = value + 1
-                            WHERE collection = 'coordinated_mtime_storage_counter'
-                            AND name = 'service_container_counter'";
-    if (!empty($configuration['db_query_update'])) {
-      $this->dbQueryUpdate = $configuration['db_query_update'];
+  /**
+   * Increment the counter for the service container path.
+   */
+  protected function incrementCounter() {
+    if ($this->incrementCallable) {
+      $callable = $this->incrementCallable;
+      $callable();
     }
-
-    $this->dbTarget = 'default';
-    if (!empty($configuration['db_target'])) {
-      $this->dbTarget = $configuration['db_target'];
+    else {
+      try {
+        $sql = "INSERT INTO {key_value} (collection, name, value)
+                VALUES ('coordinated_mtime_storage_counter', 'service_container_counter', 1)";
+        Database::getConnection()
+          ->query($sql);
+      }
+      catch (\Exception $e) {
+        $sql = "UPDATE {key_value}
+                SET value = value + 1
+                WHERE collection = 'coordinated_mtime_storage_counter'
+                AND name = 'service_container_counter'";
+        Database::getConnection()
+          ->query($sql);
+      }
     }
   }
 
   /**
-   * Returns the full path where the file is or should be stored.
+   * {@inheritdoc}
    */
   public function getFullPath($name, &$directory = NULL, &$directory_mtime = NULL) {
     if (!isset($directory)) {
@@ -104,9 +113,7 @@ public function getFullPath($name, &$directory = NULL, &$directory_mtime = NULL)
       $directory_mtime = file_exists($directory) ? filemtime($directory) : 0;
     }
 
-    $counter = Database::getConnection($this->dbTarget)
-      ->query($this->dbQueryFetch)
-      ->fetchColumn();
+    $counter = $this->fetchCounter();
     $counter = $counter ? $counter : '0';
     $path = $directory . '/' . hash_hmac('sha256', $name, $this->secret . $directory_mtime) . ".$counter.php";
     return $path;
@@ -116,17 +123,8 @@ public function getFullPath($name, &$directory = NULL, &$directory_mtime = NULL)
    * {@inheritdoc}
    */
   public function deleteAll() {
+    $this->incrementCounter();
     parent::deleteAll();
-    try {
-      Database::getConnection($this->dbTarget)
-        ->query($this->dbQueryInit);
-    }
-    catch (\Exception $e) {
-      // We don't care if this fails - that means another process beat us to
-      // it, so now we can just update.
-    }
-    Database::getConnection($this->dbTarget)
-      ->query($this->dbQueryUpdate);
   }
 
 }
