From 4a677afc98db977d546d54017b0bee71ffd6e226 Mon Sep 17 00:00:00 2001
From: webchick <webchick@24967.no-reply.drupal.org>
Date: Sun, 26 Aug 2012 14:27:30 -0700
Subject: [PATCH] Issue #1754142 by Damien Tournoud: Move CACHE_PERMANENT out
 of bootstrap.inc.

---
 core/includes/bootstrap.inc                        |  7 -------
 core/includes/common.inc                           |  7 ++++---
 .../Drupal/Core/Cache/CacheBackendInterface.php    | 13 ++++++++++---
 core/lib/Drupal/Core/Cache/DatabaseBackend.php     |  4 ++--
 core/lib/Drupal/Core/Cache/InstallBackend.php      |  2 +-
 core/lib/Drupal/Core/Cache/MemoryBackend.php       |  2 +-
 core/lib/Drupal/Core/Cache/NullBackend.php         |  2 +-
 .../Cache/GenericCacheBackendUnitTestBase.php      | 14 +++++++-------
 core/modules/update/update.module                  |  4 ++--
 9 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index 43cc27ee7ce7..56e5f437b340 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -36,13 +36,6 @@
  */
 const DRUPAL_MINIMUM_PHP_MEMORY_LIMIT = '32M';
 
-/**
- * Indicates that the item should never be removed unless explicitly selected.
- *
- * The item may be removed using cache()->delete() with a cache ID.
- */
-const CACHE_PERMANENT = 0;
-
 /**
  * @defgroup logging_severity_levels Logging severity levels
  * @{
diff --git a/core/includes/common.inc b/core/includes/common.inc
index e3f405fb9079..44fa3674df94 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -3,6 +3,7 @@
 use Drupal\Component\Utility\NestedArray;
 use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
+use Drupal\Core\Cache\CacheBackendInterface;
 use Drupal\Core\Database\Database;
 use Drupal\Core\Template\Attribute;
 
@@ -4988,7 +4989,7 @@ function drupal_page_set_cache($body) {
         'headers' => array(),
       ),
       'tags' => array('content' => TRUE),
-      'expire' => CACHE_PERMANENT,
+      'expire' => CacheBackendInterface::CACHE_PERMANENT,
       'created' => REQUEST_TIME,
     );
 
@@ -5908,7 +5909,7 @@ function drupal_render_cache_set(&$markup, $elements) {
     $data['#attached'] = $attached;
   }
   $bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'cache';
-  $expire = isset($elements['#cache']['expire']) ? $elements['#cache']['expire'] : CACHE_PERMANENT;
+  $expire = isset($elements['#cache']['expire']) ? $elements['#cache']['expire'] : CacheBackendInterface::CACHE_PERMANENT;
   $tags = isset($elements['#cache']['tags']) ? $elements['#cache']['tags'] : array();
   cache($bin)->set($cid, $data, $expire, $tags);
 }
@@ -5983,7 +5984,7 @@ function drupal_render_collect_attached($elements, $return = FALSE) {
  *   - #pre_render: $function with a _pre_render suffix.
  *   - #cache: An associative array prepared for drupal_render_cache_set().
  */
-function drupal_render_cache_by_query($query, $function, $expire = CACHE_PERMANENT, $granularity = NULL) {
+function drupal_render_cache_by_query($query, $function, $expire = CacheBackendInterface::CACHE_PERMANENT, $granularity = NULL) {
   $cache_keys = array_merge(array($function), drupal_render_cid_parts($granularity));
   $query->preExecute();
   $cache_keys[] = hash('sha256', serialize(array((string) $query, $query->getArguments())));
diff --git a/core/lib/Drupal/Core/Cache/CacheBackendInterface.php b/core/lib/Drupal/Core/Cache/CacheBackendInterface.php
index 7fef75b603e8..21409605320d 100644
--- a/core/lib/Drupal/Core/Cache/CacheBackendInterface.php
+++ b/core/lib/Drupal/Core/Cache/CacheBackendInterface.php
@@ -47,6 +47,13 @@
  */
 interface CacheBackendInterface {
 
+  /**
+   * Indicates that the item should never be removed unless explicitly selected.
+   *
+   * The item may be removed using cache()->delete() with a cache ID.
+   */
+  const CACHE_PERMANENT = 0;
+
   /**
    * Constructs a new cache backend.
    *
@@ -93,8 +100,8 @@ function getMultiple(&$cids);
    *   Strings will be stored as plain text and not serialized.
    * @param $expire
    *   One of the following values:
-   *   - CACHE_PERMANENT: Indicates that the item should never be removed unless
-   *     explicitly told to using cache->delete($cid).
+   *   - CacheBackendInterface::CACHE_PERMANENT: Indicates that the item
+   *     should never be removed unless cache->delete($cid) is used explicitly.
    *   - A Unix timestamp: Indicates that the item should be kept at least until
    *     the given time.
    * @param array $tags
@@ -104,7 +111,7 @@ function getMultiple(&$cids);
    *   a node, both the node ID and the author's user ID might be passed in as
    *   tags. For example array('node' => array(123), 'user' => array(92)).
    */
-  function set($cid, $data, $expire = CACHE_PERMANENT, array $tags = array());
+  function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANENT, array $tags = array());
 
   /**
    * Deletes an item from the cache.
diff --git a/core/lib/Drupal/Core/Cache/DatabaseBackend.php b/core/lib/Drupal/Core/Cache/DatabaseBackend.php
index e90e2ad76a85..b44f18f8c56b 100644
--- a/core/lib/Drupal/Core/Cache/DatabaseBackend.php
+++ b/core/lib/Drupal/Core/Cache/DatabaseBackend.php
@@ -117,7 +117,7 @@ protected function prepareItem($cache) {
   /**
    * Implements Drupal\Core\Cache\CacheBackendInterface::set().
    */
-  function set($cid, $data, $expire = CACHE_PERMANENT, array $tags = array()) {
+  function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANENT, array $tags = array()) {
     $fields = array(
       'serialized' => 0,
       'created' => REQUEST_TIME,
@@ -188,7 +188,7 @@ function flush() {
    */
   function expire() {
     db_delete($this->bin)
-      ->condition('expire', CACHE_PERMANENT, '<>')
+      ->condition('expire', CacheBackendInterface::CACHE_PERMANENT, '<>')
       ->condition('expire', REQUEST_TIME, '<')
       ->execute();
   }
diff --git a/core/lib/Drupal/Core/Cache/InstallBackend.php b/core/lib/Drupal/Core/Cache/InstallBackend.php
index b527d56c32cb..b5076840b852 100644
--- a/core/lib/Drupal/Core/Cache/InstallBackend.php
+++ b/core/lib/Drupal/Core/Cache/InstallBackend.php
@@ -50,7 +50,7 @@ function getMultiple(&$cids) {
   /**
    * Overrides Drupal\Core\Cache\DatabaseBackend::set().
    */
-  function set($cid, $data, $expire = CACHE_PERMANENT, array $tags = array()) {}
+  function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANENT, array $tags = array()) {}
 
   /**
    * Overrides Drupal\Core\Cache\DatabaseBackend::delete().
diff --git a/core/lib/Drupal/Core/Cache/MemoryBackend.php b/core/lib/Drupal/Core/Cache/MemoryBackend.php
index 1cd5f84fdd48..14b6a6cc6e37 100644
--- a/core/lib/Drupal/Core/Cache/MemoryBackend.php
+++ b/core/lib/Drupal/Core/Cache/MemoryBackend.php
@@ -95,7 +95,7 @@ protected function prepareItem($cache) {
   /**
    * Implements Drupal\Core\Cache\CacheBackendInterface::set().
    */
-  public function set($cid, $data, $expire = CACHE_PERMANENT, array $tags = array()) {
+  public function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANENT, array $tags = array()) {
     $this->cache[$cid] = (object) array(
       'cid' => $cid,
       'data' => $data,
diff --git a/core/lib/Drupal/Core/Cache/NullBackend.php b/core/lib/Drupal/Core/Cache/NullBackend.php
index 0408fc3efad2..dedd0333254f 100644
--- a/core/lib/Drupal/Core/Cache/NullBackend.php
+++ b/core/lib/Drupal/Core/Cache/NullBackend.php
@@ -42,7 +42,7 @@ function getMultiple(&$cids) {
   /**
    * Implements Drupal\Core\Cache\CacheBackendInterface::set().
    */
-  function set($cid, $data, $expire = CACHE_PERMANENT, array $tags = array()) {}
+  function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANENT, array $tags = array()) {}
 
   /**
    * Implements Drupal\Core\Cache\CacheBackendInterface::delete().
diff --git a/core/modules/system/lib/Drupal/system/Tests/Cache/GenericCacheBackendUnitTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Cache/GenericCacheBackendUnitTestBase.php
index 931b46d6cb4a..66c0043201fb 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Cache/GenericCacheBackendUnitTestBase.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Cache/GenericCacheBackendUnitTestBase.php
@@ -377,7 +377,7 @@ public function testFlush() {
     $backend = $this->getCacheBackend();
 
     // Set both expiring and permanent keys.
-    $backend->set('test1', 1, CACHE_PERMANENT);
+    $backend->set('test1', 1, CacheBackendInterface::CACHE_PERMANENT);
     $backend->set('test2', 3, time() + 1000);
 
     $backend->flush();
@@ -411,8 +411,8 @@ function testClearTags() {
     $backend = $this->getCacheBackend();
 
     // Create two cache entries with the same tag and tag value.
-    $backend->set('test_cid_clear1', $this->defaultValue, CACHE_PERMANENT, array('test_tag' => array(1)));
-    $backend->set('test_cid_clear2', $this->defaultValue, CACHE_PERMANENT, array('test_tag' => array(1)));
+    $backend->set('test_cid_clear1', $this->defaultValue, CacheBackendInterface::CACHE_PERMANENT, array('test_tag' => array(1)));
+    $backend->set('test_cid_clear2', $this->defaultValue, CacheBackendInterface::CACHE_PERMANENT, array('test_tag' => array(1)));
     $this->assertTrue($this->checkCacheExists('test_cid_clear1')
                       && $this->checkCacheExists('test_cid_clear2'),
                       'Two cache items were created.');
@@ -423,9 +423,9 @@ function testClearTags() {
                       'Two caches removed after clearing a cache tag.');
 
     // Create three cache entries with a mix of tags and tag values.
-    $backend->set('test_cid_clear1', $this->defaultValue, CACHE_PERMANENT, array('test_tag' => array(1)));
-    $backend->set('test_cid_clear2', $this->defaultValue, CACHE_PERMANENT, array('test_tag' => array(2)));
-    $backend->set('test_cid_clear3', $this->defaultValue, CACHE_PERMANENT, array('test_tag_foo' => array(3)));
+    $backend->set('test_cid_clear1', $this->defaultValue, CacheBackendInterface::CACHE_PERMANENT, array('test_tag' => array(1)));
+    $backend->set('test_cid_clear2', $this->defaultValue, CacheBackendInterface::CACHE_PERMANENT, array('test_tag' => array(2)));
+    $backend->set('test_cid_clear3', $this->defaultValue, CacheBackendInterface::CACHE_PERMANENT, array('test_tag_foo' => array(3)));
     $this->assertTrue($this->checkCacheExists('test_cid_clear1')
                       && $this->checkCacheExists('test_cid_clear2')
                       && $this->checkCacheExists('test_cid_clear3'),
@@ -443,7 +443,7 @@ function testClearTags() {
     $tags = array('test_tag' => array(1, 2, 3));
     $bins = array('path', 'bootstrap', 'page');
     foreach ($bins as $bin) {
-      $this->getCacheBackend($bin)->set('test', $this->defaultValue, CACHE_PERMANENT, $tags);
+      $this->getCacheBackend($bin)->set('test', $this->defaultValue, CacheBackendInterface::CACHE_PERMANENT, $tags);
       $this->assertTrue($this->checkCacheExists('test', $bin), 'Cache item was set in bin.');
     }
 
diff --git a/core/modules/update/update.module b/core/modules/update/update.module
index d1c4957f81f2..bee906fd8386 100644
--- a/core/modules/update/update.module
+++ b/core/modules/update/update.module
@@ -750,8 +750,8 @@ function update_verify_update_archive($project, $archive_file, $directory) {
  *   The data to store.
  * @param $expire
  *   One of the following values:
- *   - CACHE_PERMANENT: Indicates that the item should never be removed except
- *     by explicitly using _update_cache_clear().
+ *   - CacheBackendInterface::CACHE_PERMANENT: Indicates that the item should
+ *     never be removed except by explicitly using _update_cache_clear().
  *   - A Unix timestamp: Indicates that the item should be kept at least until
  *     the given time, after which it will be invalidated.
  *
-- 
GitLab