Issue #1754142 by Damien Tournoud: Move CACHE_PERMANENT out of bootstrap.inc.
parent
16005119bc
commit
4a677afc98
|
@ -36,13 +36,6 @@ const DRUPAL_MINIMUM_PHP = '5.3.3';
|
||||||
*/
|
*/
|
||||||
const DRUPAL_MINIMUM_PHP_MEMORY_LIMIT = '32M';
|
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
|
* @defgroup logging_severity_levels Logging severity levels
|
||||||
* @{
|
* @{
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
use Drupal\Component\Utility\NestedArray;
|
use Drupal\Component\Utility\NestedArray;
|
||||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
use Drupal\Core\Cache\CacheBackendInterface;
|
||||||
use Drupal\Core\Database\Database;
|
use Drupal\Core\Database\Database;
|
||||||
use Drupal\Core\Template\Attribute;
|
use Drupal\Core\Template\Attribute;
|
||||||
|
|
||||||
|
@ -4988,7 +4989,7 @@ function drupal_page_set_cache($body) {
|
||||||
'headers' => array(),
|
'headers' => array(),
|
||||||
),
|
),
|
||||||
'tags' => array('content' => TRUE),
|
'tags' => array('content' => TRUE),
|
||||||
'expire' => CACHE_PERMANENT,
|
'expire' => CacheBackendInterface::CACHE_PERMANENT,
|
||||||
'created' => REQUEST_TIME,
|
'created' => REQUEST_TIME,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -5908,7 +5909,7 @@ function drupal_render_cache_set(&$markup, $elements) {
|
||||||
$data['#attached'] = $attached;
|
$data['#attached'] = $attached;
|
||||||
}
|
}
|
||||||
$bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'cache';
|
$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();
|
$tags = isset($elements['#cache']['tags']) ? $elements['#cache']['tags'] : array();
|
||||||
cache($bin)->set($cid, $data, $expire, $tags);
|
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.
|
* - #pre_render: $function with a _pre_render suffix.
|
||||||
* - #cache: An associative array prepared for drupal_render_cache_set().
|
* - #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));
|
$cache_keys = array_merge(array($function), drupal_render_cid_parts($granularity));
|
||||||
$query->preExecute();
|
$query->preExecute();
|
||||||
$cache_keys[] = hash('sha256', serialize(array((string) $query, $query->getArguments())));
|
$cache_keys[] = hash('sha256', serialize(array((string) $query, $query->getArguments())));
|
||||||
|
|
|
@ -47,6 +47,13 @@ namespace Drupal\Core\Cache;
|
||||||
*/
|
*/
|
||||||
interface CacheBackendInterface {
|
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.
|
* Constructs a new cache backend.
|
||||||
*
|
*
|
||||||
|
@ -93,8 +100,8 @@ interface CacheBackendInterface {
|
||||||
* Strings will be stored as plain text and not serialized.
|
* Strings will be stored as plain text and not serialized.
|
||||||
* @param $expire
|
* @param $expire
|
||||||
* One of the following values:
|
* One of the following values:
|
||||||
* - CACHE_PERMANENT: Indicates that the item should never be removed unless
|
* - CacheBackendInterface::CACHE_PERMANENT: Indicates that the item
|
||||||
* explicitly told to using cache->delete($cid).
|
* should never be removed unless cache->delete($cid) is used explicitly.
|
||||||
* - A Unix timestamp: Indicates that the item should be kept at least until
|
* - A Unix timestamp: Indicates that the item should be kept at least until
|
||||||
* the given time.
|
* the given time.
|
||||||
* @param array $tags
|
* @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
|
* 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)).
|
* 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.
|
* Deletes an item from the cache.
|
||||||
|
|
|
@ -117,7 +117,7 @@ class DatabaseBackend implements CacheBackendInterface {
|
||||||
/**
|
/**
|
||||||
* Implements Drupal\Core\Cache\CacheBackendInterface::set().
|
* 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(
|
$fields = array(
|
||||||
'serialized' => 0,
|
'serialized' => 0,
|
||||||
'created' => REQUEST_TIME,
|
'created' => REQUEST_TIME,
|
||||||
|
@ -188,7 +188,7 @@ class DatabaseBackend implements CacheBackendInterface {
|
||||||
*/
|
*/
|
||||||
function expire() {
|
function expire() {
|
||||||
db_delete($this->bin)
|
db_delete($this->bin)
|
||||||
->condition('expire', CACHE_PERMANENT, '<>')
|
->condition('expire', CacheBackendInterface::CACHE_PERMANENT, '<>')
|
||||||
->condition('expire', REQUEST_TIME, '<')
|
->condition('expire', REQUEST_TIME, '<')
|
||||||
->execute();
|
->execute();
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ class InstallBackend extends DatabaseBackend {
|
||||||
/**
|
/**
|
||||||
* Overrides Drupal\Core\Cache\DatabaseBackend::set().
|
* 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().
|
* Overrides Drupal\Core\Cache\DatabaseBackend::delete().
|
||||||
|
|
|
@ -95,7 +95,7 @@ class MemoryBackend implements CacheBackendInterface {
|
||||||
/**
|
/**
|
||||||
* Implements Drupal\Core\Cache\CacheBackendInterface::set().
|
* 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(
|
$this->cache[$cid] = (object) array(
|
||||||
'cid' => $cid,
|
'cid' => $cid,
|
||||||
'data' => $data,
|
'data' => $data,
|
||||||
|
|
|
@ -42,7 +42,7 @@ class NullBackend implements CacheBackendInterface {
|
||||||
/**
|
/**
|
||||||
* Implements Drupal\Core\Cache\CacheBackendInterface::set().
|
* 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().
|
* Implements Drupal\Core\Cache\CacheBackendInterface::delete().
|
||||||
|
|
|
@ -377,7 +377,7 @@ abstract class GenericCacheBackendUnitTestBase extends UnitTestBase {
|
||||||
$backend = $this->getCacheBackend();
|
$backend = $this->getCacheBackend();
|
||||||
|
|
||||||
// Set both expiring and permanent keys.
|
// 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->set('test2', 3, time() + 1000);
|
||||||
|
|
||||||
$backend->flush();
|
$backend->flush();
|
||||||
|
@ -411,8 +411,8 @@ abstract class GenericCacheBackendUnitTestBase extends UnitTestBase {
|
||||||
$backend = $this->getCacheBackend();
|
$backend = $this->getCacheBackend();
|
||||||
|
|
||||||
// Create two cache entries with the same tag and tag value.
|
// 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_clear1', $this->defaultValue, CacheBackendInterface::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_clear2', $this->defaultValue, CacheBackendInterface::CACHE_PERMANENT, array('test_tag' => array(1)));
|
||||||
$this->assertTrue($this->checkCacheExists('test_cid_clear1')
|
$this->assertTrue($this->checkCacheExists('test_cid_clear1')
|
||||||
&& $this->checkCacheExists('test_cid_clear2'),
|
&& $this->checkCacheExists('test_cid_clear2'),
|
||||||
'Two cache items were created.');
|
'Two cache items were created.');
|
||||||
|
@ -423,9 +423,9 @@ abstract class GenericCacheBackendUnitTestBase extends UnitTestBase {
|
||||||
'Two caches removed after clearing a cache tag.');
|
'Two caches removed after clearing a cache tag.');
|
||||||
|
|
||||||
// Create three cache entries with a mix of tags and tag values.
|
// 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_clear1', $this->defaultValue, CacheBackendInterface::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_clear2', $this->defaultValue, CacheBackendInterface::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_clear3', $this->defaultValue, CacheBackendInterface::CACHE_PERMANENT, array('test_tag_foo' => array(3)));
|
||||||
$this->assertTrue($this->checkCacheExists('test_cid_clear1')
|
$this->assertTrue($this->checkCacheExists('test_cid_clear1')
|
||||||
&& $this->checkCacheExists('test_cid_clear2')
|
&& $this->checkCacheExists('test_cid_clear2')
|
||||||
&& $this->checkCacheExists('test_cid_clear3'),
|
&& $this->checkCacheExists('test_cid_clear3'),
|
||||||
|
@ -443,7 +443,7 @@ abstract class GenericCacheBackendUnitTestBase extends UnitTestBase {
|
||||||
$tags = array('test_tag' => array(1, 2, 3));
|
$tags = array('test_tag' => array(1, 2, 3));
|
||||||
$bins = array('path', 'bootstrap', 'page');
|
$bins = array('path', 'bootstrap', 'page');
|
||||||
foreach ($bins as $bin) {
|
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.');
|
$this->assertTrue($this->checkCacheExists('test', $bin), 'Cache item was set in bin.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -750,8 +750,8 @@ function update_verify_update_archive($project, $archive_file, $directory) {
|
||||||
* The data to store.
|
* The data to store.
|
||||||
* @param $expire
|
* @param $expire
|
||||||
* One of the following values:
|
* One of the following values:
|
||||||
* - CACHE_PERMANENT: Indicates that the item should never be removed except
|
* - CacheBackendInterface::CACHE_PERMANENT: Indicates that the item should
|
||||||
* by explicitly using _update_cache_clear().
|
* never be removed except by explicitly using _update_cache_clear().
|
||||||
* - A Unix timestamp: Indicates that the item should be kept at least until
|
* - A Unix timestamp: Indicates that the item should be kept at least until
|
||||||
* the given time, after which it will be invalidated.
|
* the given time, after which it will be invalidated.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue