diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 43cc27ee7ce..56e5f437b34 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -36,13 +36,6 @@ const DRUPAL_MINIMUM_PHP = '5.3.3'; */ 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 e3f405fb907..44fa3674df9 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 7fef75b603e..21409605320 100644 --- a/core/lib/Drupal/Core/Cache/CacheBackendInterface.php +++ b/core/lib/Drupal/Core/Cache/CacheBackendInterface.php @@ -47,6 +47,13 @@ namespace Drupal\Core\Cache; */ 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 @@ interface CacheBackendInterface { * 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 @@ interface CacheBackendInterface { * 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 e90e2ad76a8..b44f18f8c56 100644 --- a/core/lib/Drupal/Core/Cache/DatabaseBackend.php +++ b/core/lib/Drupal/Core/Cache/DatabaseBackend.php @@ -117,7 +117,7 @@ class DatabaseBackend implements CacheBackendInterface { /** * 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 @@ class DatabaseBackend implements CacheBackendInterface { */ 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 b527d56c32c..b5076840b85 100644 --- a/core/lib/Drupal/Core/Cache/InstallBackend.php +++ b/core/lib/Drupal/Core/Cache/InstallBackend.php @@ -50,7 +50,7 @@ class InstallBackend extends DatabaseBackend { /** * 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 1cd5f84fdd4..14b6a6cc6e3 100644 --- a/core/lib/Drupal/Core/Cache/MemoryBackend.php +++ b/core/lib/Drupal/Core/Cache/MemoryBackend.php @@ -95,7 +95,7 @@ class MemoryBackend implements CacheBackendInterface { /** * 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 0408fc3efad..dedd0333254 100644 --- a/core/lib/Drupal/Core/Cache/NullBackend.php +++ b/core/lib/Drupal/Core/Cache/NullBackend.php @@ -42,7 +42,7 @@ class NullBackend implements CacheBackendInterface { /** * 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 931b46d6cb4..66c0043201f 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 @@ abstract class GenericCacheBackendUnitTestBase extends UnitTestBase { $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 @@ abstract class GenericCacheBackendUnitTestBase extends UnitTestBase { $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 @@ abstract class GenericCacheBackendUnitTestBase extends UnitTestBase { '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 @@ abstract class GenericCacheBackendUnitTestBase extends UnitTestBase { $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 d1c4957f81f..bee906fd838 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. *