Commit a1a5e155 authored by alexpott's avatar alexpott

Issue #2198343 by damiankloip, longwave: Convert all usages of cache() and...

Issue #2198343 by damiankloip, longwave: Convert all usages of cache() and cache_invalidate_tags() procedural functions.
parent 96e7aa9a
......@@ -24,6 +24,9 @@
* The cache object associated with the specified bin.
*
* @see \Drupal\Core\Cache\CacheBackendInterface
*
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
* Use \Drupal::cache().
*/
function cache($bin = 'cache') {
return \Drupal::cache($bin);
......
......@@ -3197,7 +3197,7 @@ function drupal_page_set_cache(Response $response, Request $request) {
if ($page_compressed) {
$cache->data['body'] = gzencode($cache->data['body'], 9, FORCE_GZIP);
}
cache('page')->set($cache->cid, $cache->data, $cache->expire, $cache->tags);
\Drupal::cache('page')->set($cache->cid, $cache->data, $cache->expire, $cache->tags);
}
return $cache;
}
......@@ -4091,7 +4091,7 @@ function drupal_render_cache_get(array $elements) {
}
$bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'cache';
if (!empty($cid) && $cache = cache($bin)->get($cid)) {
if (!empty($cid) && $cache = \Drupal::cache($bin)->get($cid)) {
$cached_element = $cache->data;
// Add additional libraries, JavaScript, CSS and other data attached
// to this element.
......@@ -4145,7 +4145,7 @@ function drupal_render_cache_set(&$markup, array $elements) {
$bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'cache';
$expire = isset($elements['#cache']['expire']) ? $elements['#cache']['expire'] : Cache::PERMANENT;
$tags = drupal_render_collect_cache_tags($elements);
cache($bin)->set($cid, $data, $expire, $tags);
\Drupal::cache($bin)->set($cid, $data, $expire, $tags);
}
/**
......@@ -4433,7 +4433,7 @@ function drupal_cache_tags_page_get(Response $response) {
* added to this string and is also part of the cache key in
* drupal_render_cache_set() and drupal_render_cache_get().
* @param $expire
* The cache expire time, passed eventually to cache()->set().
* The cache expire time, passed eventually to \Drupal::cache()->set().
* @param $granularity
* One or more granularity constants passed to drupal_render_cid_parts().
*
......
......@@ -94,7 +94,7 @@ function entity_get_form_modes($entity_type = NULL) {
$form_modes = &drupal_static(__FUNCTION__);
if (!$form_modes) {
$langcode = language(Language::TYPE_INTERFACE)->id;
if ($cache = cache()->get("entity_form_mode_info:$langcode")) {
if ($cache = \Drupal::cache()->get("entity_form_mode_info:$langcode")) {
$form_modes = $cache->data;
}
else {
......@@ -104,7 +104,7 @@ function entity_get_form_modes($entity_type = NULL) {
$form_modes[$form_mode_entity_type][$form_mode_name] = (array) $form_mode;
}
drupal_alter('entity_form_mode_info', $form_modes);
cache()->set("entity_form_mode_info:$langcode", $form_modes, Cache::PERMANENT, array('entity_types' => TRUE));
\Drupal::cache()->set("entity_form_mode_info:$langcode", $form_modes, Cache::PERMANENT, array('entity_types' => TRUE));
}
}
......@@ -132,7 +132,7 @@ function entity_get_view_modes($entity_type = NULL) {
$view_modes = &drupal_static(__FUNCTION__);
if (!$view_modes) {
$langcode = language(Language::TYPE_INTERFACE)->id;
if ($cache = cache()->get("entity_view_mode_info:$langcode")) {
if ($cache = \Drupal::cache()->get("entity_view_mode_info:$langcode")) {
$view_modes = $cache->data;
}
else {
......@@ -142,7 +142,7 @@ function entity_get_view_modes($entity_type = NULL) {
$view_modes[$view_mode_entity_type][$view_mode_name] = (array) $view_mode;
}
drupal_alter('entity_view_mode_info', $view_modes);
cache()->set("entity_view_mode_info:$langcode", $view_modes, Cache::PERMANENT, array('entity_types' => TRUE));
\Drupal::cache()->set("entity_view_mode_info:$langcode", $view_modes, Cache::PERMANENT, array('entity_types' => TRUE));
}
}
......
......@@ -1086,7 +1086,7 @@ function menu_tree_all_data($menu_name, $link = NULL, $max_depth = NULL) {
if (!isset($tree[$cid])) {
// If the static variable doesn't have the data, check {cache_menu}.
$cache = cache('menu')->get($cid);
$cache = \Drupal::cache('menu')->get($cid);
if ($cache && isset($cache->data)) {
// If the cache entry exists, it contains the parameters for
// menu_build_tree().
......@@ -1113,7 +1113,7 @@ function menu_tree_all_data($menu_name, $link = NULL, $max_depth = NULL) {
}
// Cache the tree building parameters using the page-specific cid.
cache('menu')->set($cid, $tree_parameters, Cache::PERMANENT, array('menu' => $menu_name));
\Drupal::cache('menu')->set($cid, $tree_parameters, Cache::PERMANENT, array('menu' => $menu_name));
}
// Build the tree using the parameters; the resulting tree will be cached
......@@ -1231,7 +1231,7 @@ function menu_tree_page_data($menu_name, $max_depth = NULL, $only_active_trail =
if (!isset($tree[$cid])) {
// If the static variable doesn't have the data, check {cache_menu}.
$cache = cache('menu')->get($cid);
$cache = \Drupal::cache('menu')->get($cid);
if ($cache && isset($cache->data)) {
// If the cache entry exists, it contains the parameters for
// menu_build_tree().
......@@ -1299,7 +1299,7 @@ function menu_tree_page_data($menu_name, $max_depth = NULL, $only_active_trail =
$tree_parameters['active_trail'] = $active_trail;
}
// Cache the tree building parameters using the page-specific cid.
cache('menu')->set($cid, $tree_parameters, Cache::PERMANENT, array('menu' => $menu_name));
\Drupal::cache('menu')->set($cid, $tree_parameters, Cache::PERMANENT, array('menu' => $menu_name));
}
// Build the tree using the parameters; the resulting tree will be cached
......@@ -1367,7 +1367,7 @@ function _menu_build_tree($menu_name, array $parameters = array()) {
// If we do not have this tree in the static cache, check {cache_menu}.
if (!isset($trees[$tree_cid])) {
$cache = cache('menu')->get($tree_cid);
$cache = \Drupal::cache('menu')->get($tree_cid);
if ($cache && isset($cache->data)) {
$trees[$tree_cid] = $cache->data;
}
......@@ -1410,7 +1410,7 @@ function _menu_build_tree($menu_name, array $parameters = array()) {
menu_tree_collect_node_links($data['tree'], $data['node_links']);
// Cache the data, if it is not already in the cache.
cache('menu')->set($tree_cid, $data, Cache::PERMANENT, array('menu' => $menu_name));
\Drupal::cache('menu')->set($tree_cid, $data, Cache::PERMANENT, array('menu' => $menu_name));
$trees[$tree_cid] = $data;
}
......@@ -2370,7 +2370,7 @@ function menu_get_active_trail() {
* might have been made to the router items or menu links.
*/
function menu_cache_clear_all() {
cache('menu')->deleteAll();
\Drupal::cache('menu')->deleteAll();
menu_reset_static_cache();
}
......@@ -2720,13 +2720,13 @@ function _menu_clear_page_cache() {
// Clear the page and block caches, but at most twice, including at
// the end of the page load when there are multiple links saved or deleted.
if ($cache_cleared == 0) {
cache_invalidate_tags(array('content' => TRUE));
Cache::invalidateTags(array('content' => TRUE));
// Keep track of which menus have expanded items.
_menu_set_expanded_menus();
$cache_cleared = 1;
}
elseif ($cache_cleared == 1) {
drupal_register_shutdown_function('cache_invalidate_tags', array('content' => TRUE));
drupal_register_shutdown_function('Drupal\Core\Cache\Cache::invalidateTags', array('content' => TRUE));
// Keep track of which menus have expanded items.
drupal_register_shutdown_function('_menu_set_expanded_menus');
$cache_cleared = 2;
......
......@@ -30,7 +30,7 @@
*/
function system_list($type) {
$lists = &drupal_static(__FUNCTION__);
if ($cached = cache('bootstrap')->get('system_list')) {
if ($cached = \Drupal::cache('bootstrap')->get('system_list')) {
$lists = $cached->data;
}
else {
......@@ -92,7 +92,7 @@ function system_list($type) {
// Set the theme engine prefix.
$lists['theme'][$key]->prefix = ($lists['theme'][$key]->info['engine'] == 'theme') ? $base_key : $lists['theme'][$key]->info['engine'];
}
cache('bootstrap')->set('system_list', $lists);
\Drupal::cache('bootstrap')->set('system_list', $lists);
}
// To avoid a separate database lookup for the filepath, prime the
// drupal_get_filename() static cache with all enabled modules and themes.
......@@ -110,8 +110,8 @@ function system_list_reset() {
drupal_static_reset('system_list');
drupal_static_reset('system_rebuild_module_data');
drupal_static_reset('list_themes');
cache('bootstrap')->delete('system_list');
cache()->delete('system_info');
\Drupal::cache('bootstrap')->delete('system_list');
\Drupal::cache()->delete('system_info');
// Remove last known theme data state.
// This causes system_list() to call system_rebuild_theme_data() on its next
// invocation. When enabling a module that implements hook_system_info_alter()
......
......@@ -65,7 +65,7 @@ function drupal_get_complete_schema($rebuild = FALSE) {
if (!isset($schema) || $rebuild) {
// Try to load the schema from cache.
if (!$rebuild && $cached = cache()->get('schema')) {
if (!$rebuild && $cached = \Drupal::cache()->get('schema')) {
$schema = $cached->data;
}
// Otherwise, rebuild the schema cache.
......@@ -82,7 +82,7 @@ function drupal_get_complete_schema($rebuild = FALSE) {
// That would break modules which use $schema further down the line.
$current = (array) \Drupal::moduleHandler()->invoke($module, 'schema');
// Set 'module' and 'name' keys for each table, and remove descriptions,
// as they needlessly slow down cache()->get() for every single request.
// as they needlessly slow down \Drupal::cache()->get() for every single request.
_drupal_schema_initialize($current, $module);
$schema = array_merge($schema, $current);
}
......@@ -94,7 +94,7 @@ function drupal_get_complete_schema($rebuild = FALSE) {
// If the schema is empty, avoid saving it: some database engines require
// the schema to perform queries, and this could lead to infinite loops.
if (!empty($schema) && (drupal_get_bootstrap_phase() == DRUPAL_BOOTSTRAP_FULL)) {
cache()->set('schema', $schema, Cache::PERMANENT, array('schema' => TRUE));
\Drupal::cache()->set('schema', $schema, Cache::PERMANENT, array('schema' => TRUE));
}
}
}
......
......@@ -38,8 +38,8 @@
* To access your custom cache bin, specify the name of the bin when storing
* or retrieving cached data:
* @code
* cache('custom_bin')->set($cid, $data, $expire);
* cache('custom_bin')->get($cid);
* \Drupal::cache('custom_bin')->set($cid, $data, $expire);
* \Drupal::cache('custom_bin')->get($cid);
* @endcode
*
* There are two ways to "remove" a cache item:
......@@ -66,7 +66,7 @@
* the other requests can proceed using the stale value. As soon as the cache
* item has been updated, all future requests will use the updated value.
*
* @see cache()
* @see \Drupal::cache()
* @see \Drupal\Core\Cache\DatabaseBackend
*/
interface CacheBackendInterface {
......
......@@ -134,7 +134,7 @@ protected function loadFieldItems(array $entities) {
foreach ($entities as $id => $entity) {
$cids[] = "field:{$this->entityTypeId}:$id";
}
$cache = cache('field')->getMultiple($cids);
$cache = \Drupal::cache('field')->getMultiple($cids);
// Put the cached field values back into the entities and remove them from
// the list of entities to query.
foreach ($entities as $id => $entity) {
......@@ -183,7 +183,7 @@ protected function loadFieldItems(array $entities) {
}
}
$cid = "field:{$this->entityTypeId}:$id";
cache('field')->set($cid, $data);
\Drupal::cache('field')->set($cid, $data);
}
}
}
......@@ -207,7 +207,7 @@ protected function saveFieldItems(EntityInterface $entity, $update = TRUE) {
if ($update) {
$entity_type = $entity->getEntityType();
if ($entity_type->isFieldDataCacheable()) {
cache('field')->delete('field:' . $entity->getEntityTypeId() . ':' . $entity->id());
\Drupal::cache('field')->delete('field:' . $entity->getEntityTypeId() . ':' . $entity->id());
}
}
}
......@@ -227,7 +227,7 @@ protected function deleteFieldItems(EntityInterface $entity) {
$entity_type = $entity->getEntityType();
if ($entity_type->isFieldDataCacheable()) {
cache('field')->delete('field:' . $entity->getEntityTypeId() . ':' . $entity->id());
\Drupal::cache('field')->delete('field:' . $entity->getEntityTypeId() . ':' . $entity->id());
}
}
......
......@@ -36,7 +36,7 @@ class TwigEnvironment extends \Twig_Environment {
*/
public function __construct(\Twig_LoaderInterface $loader = NULL, $options = array(), ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler) {
// @todo Pass as arguments from the DIC.
$this->cache_object = cache();
$this->cache_object = \Drupal::cache();
// Set twig path namespace for themes and modules.
$namespaces = $module_handler->getModuleList();
......
......@@ -69,21 +69,21 @@
abstract class CacheArray implements \ArrayAccess {
/**
* A cid to pass to cache()->set() and cache()->get().
* A cid to pass to \Drupal::cache()->set() and \Drupal::cache()->get().
*
* @var string
*/
protected $cid;
/**
* A tags array to pass to cache()->set().
* A tags array to pass to \Drupal::cache()->set().
*
* @var array
*/
protected $tags;
/**
* A bin to pass to cache()->set() and cache()->get().
* A bin to pass to \Drupal::cache()->set() and \Drupal::cache()->get().
*
* @var string
*/
......@@ -118,7 +118,7 @@ public function __construct($cid, $bin, $tags = array()) {
$this->bin = $bin;
$this->tags = $tags;
if ($cached = cache($bin)->get($this->cid)) {
if ($cached = \Drupal::cache($bin)->get($this->cid)) {
$this->storage = $cached->data;
}
}
......@@ -203,10 +203,10 @@ protected function set($data, $lock = TRUE) {
// To implement locking for cache misses, override __construct().
$lock_name = $this->cid . ':' . $this->bin;
if (!$lock || lock()->acquire($lock_name)) {
if ($cached = cache($this->bin)->get($this->cid)) {
if ($cached = \Drupal::cache($this->bin)->get($this->cid)) {
$data = $cached->data + $data;
}
cache($this->bin)->set($this->cid, $data, Cache::PERMANENT, $this->tags);
\Drupal::cache($this->bin)->set($this->cid, $data, Cache::PERMANENT, $this->tags);
if ($lock) {
lock()->release($lock_name);
}
......@@ -219,7 +219,7 @@ protected function set($data, $lock = TRUE) {
public function clear() {
$this->storage = array();
$this->keysToPersist = array();
cache($this->bin)->delete($this->cid);
\Drupal::cache($this->bin)->delete($this->cid);
}
/**
......
......@@ -10,6 +10,7 @@
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Component\Utility\Json;
use Drupal\Component\Utility\String;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Config\Entity\ConfigEntityListController;
use Drupal\Core\Entity\EntityControllerInterface;
use Drupal\Core\Entity\EntityInterface;
......@@ -412,7 +413,7 @@ public function submitForm(array &$form, array &$form_state) {
$entity->save();
}
drupal_set_message(t('The block settings have been updated.'));
cache_invalidate_tags(array('content' => TRUE));
Cache::invalidateTags(array('content' => TRUE));
}
}
......@@ -7,6 +7,7 @@
namespace Drupal\block\Tests;
use Drupal\Core\Cache\Cache;
use Drupal\simpletest\WebTestBase;
/**
......@@ -80,7 +81,7 @@ function testCachePerRole() {
$this->assertText($old_content, 'Block is served from the cache.');
// Clear the cache and verify that the stale data is no longer there.
cache_invalidate_tags(array('content' => TRUE));
Cache::invalidateTags(array('content' => TRUE));
$this->drupalGet('');
$this->assertNoText($old_content, 'Block cache clear removes stale cache data.');
$this->assertText($current_content, 'Fresh block content is displayed after clearing the cache.');
......
......@@ -562,7 +562,7 @@ public function bookTreeAllData($menu_name, $link = NULL, $max_depth = NULL) {
if (!isset($tree[$cid])) {
// If the static variable doesn't have the data, check {cache_menu}.
$cache = cache('menu')->get($cid);
$cache = \Drupal::cache('menu')->get($cid);
if ($cache && isset($cache->data)) {
// If the cache entry exists, it contains the parameters for
// menu_build_tree().
......@@ -589,7 +589,7 @@ public function bookTreeAllData($menu_name, $link = NULL, $max_depth = NULL) {
}
// Cache the tree building parameters using the page-specific cid.
cache('menu')->set($cid, $tree_parameters, Cache::PERMANENT, array('menu' => $menu_name));
\Drupal::cache('menu')->set($cid, $tree_parameters, Cache::PERMANENT, array('menu' => $menu_name));
}
// Build the tree using the parameters; the resulting tree will be cached
......@@ -733,7 +733,7 @@ protected function _menu_build_tree($menu_name, array $parameters = array()) {
// If we do not have this tree in the static cache, check {cache_menu}.
if (!isset($trees[$tree_cid])) {
$cache = cache('menu')->get($tree_cid);
$cache = \Drupal::cache('menu')->get($tree_cid);
if ($cache && isset($cache->data)) {
$trees[$tree_cid] = $cache->data;
}
......@@ -776,7 +776,7 @@ protected function _menu_build_tree($menu_name, array $parameters = array()) {
$this->bookTreeCollectNodeLinks($data['tree'], $data['node_links']);
// Cache the data, if it is not already in the cache.
cache('menu')->set($tree_cid, $data, Cache::PERMANENT, array('menu' => $menu_name));
\Drupal::cache('menu')->set($tree_cid, $data, Cache::PERMANENT, array('menu' => $menu_name));
$trees[$tree_cid] = $data;
}
......@@ -993,12 +993,12 @@ public function bookMenuSubtreeData($link) {
$cid = 'links:' . $link['menu_name'] . ':subtree-cid:' . $link['mlid'];
if (!isset($tree[$cid])) {
$cache = cache('menu')->get($cid);
$cache = \Drupal::cache('menu')->get($cid);
if ($cache && isset($cache->data)) {
// If the cache entry exists, it will just be the cid for the actual data.
// This avoids duplication of large amounts of data.
$cache = cache('menu')->get($cache->data);
$cache = \Drupal::cache('menu')->get($cache->data);
if ($cache && isset($cache->data)) {
$data = $cache->data;
......@@ -1029,11 +1029,11 @@ public function bookMenuSubtreeData($link) {
$tree_cid = 'links:' . $item['menu_name'] . ':subtree-data:' . hash('sha256', serialize($data));
// Cache the data, if it is not already in the cache.
if (!cache('menu')->get($tree_cid)) {
cache('menu')->set($tree_cid, $data);
if (!\Drupal::cache('menu')->get($tree_cid)) {
\Drupal::cache('menu')->set($tree_cid, $data);
}
// Cache the cid of the (shared) data using the menu and item-specific cid.
cache('menu')->set($cid, $tree_cid);
\Drupal::cache('menu')->set($cid, $tree_cid);
}
// Check access for the current user to each item in the tree.
$this->bookTreeCheckAccess($data['tree'], $data['node_links']);
......
......@@ -313,7 +313,7 @@ public function getLangcodes() {
// be expensive to calculate all the time. The cache is cleared on core
// upgrades which is the only situation the CKEditor file listing should
// change.
$langcode_cache = cache('ckeditor.languages')->get('langcodes');
$langcode_cache = \Drupal::cache('ckeditor.languages')->get('langcodes');
if (!empty($langcode_cache)) {
$langcodes = $langcode_cache->data;
}
......@@ -325,7 +325,7 @@ public function getLangcodes() {
$langcode = $language_file->getBasename('.js');
$langcodes[$langcode] = $langcode;
}
cache('ckeditor.languages')->set('langcodes', $langcodes);
\Drupal::cache('ckeditor.languages')->set('langcodes', $langcodes);
}
// Get language mapping if available to map to Drupal language codes.
......
......@@ -7,6 +7,7 @@
namespace Drupal\comment\Tests;
use Drupal\Component\Utility\String;
use Drupal\Core\Cache\Cache;
/**
* Tests the Comment module blocks.
......@@ -66,7 +67,7 @@ function testRecentCommentBlock() {
user_role_revoke_permissions(DRUPAL_ANONYMOUS_RID, array('access comments'));
// drupalCreateNode() does not automatically flush content caches unlike
// posting a node from a node form.
cache_invalidate_tags(array('content' => TRUE));
Cache::invalidateTags(array('content' => TRUE));
$this->drupalGet('');
$this->assertNoText(t('Recent comments'));
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access comments'));
......
......@@ -289,7 +289,7 @@ function field_modules_uninstalled($modules) {
* Clears the field info and field data caches.
*/
function field_cache_clear() {
cache('field')->deleteAll();
\Drupal::cache('field')->deleteAll();
field_info_cache_clear();
}
......
......@@ -187,14 +187,14 @@ function testFieldAttachCache() {
$cid = "field:$entity_type:" . $entity_init->id();
// Check that no initial cache entry is present.
$this->assertFalse(cache('field')->get($cid), 'Non-cached: no initial cache entry');
$this->assertFalse(\Drupal::cache('field')->get($cid), 'Non-cached: no initial cache entry');
// Save, and check that no cache entry is present.
$entity = clone($entity_init);
$entity->{$this->field_name}->setValue($values);
$entity = $this->entitySaveReload($entity);
$cid = "field:$entity_type:" . $entity->id();
$this->assertFalse(cache('field')->get($cid), 'Non-cached: no cache entry on insert and load');
$this->assertFalse(\Drupal::cache('field')->get($cid), 'Non-cached: no cache entry on insert and load');
// Cacheable entity type.
$entity_type = 'entity_test_cache';
......@@ -207,20 +207,20 @@ function testFieldAttachCache() {
// Check that no initial cache entry is present.
$cid = "field:$entity_type:" . $entity->id();
$this->assertFalse(cache('field')->get($cid), 'Cached: no initial cache entry');
$this->assertFalse(\Drupal::cache('field')->get($cid), 'Cached: no initial cache entry');
// Save, and check that no cache entry is present.
$entity = clone($entity_init);
$entity->{$this->field_name_2} = $values;
$entity->save();
$cid = "field:$entity_type:" . $entity->id();
$this->assertFalse(cache('field')->get($cid), 'Cached: no cache entry on insert');
$this->assertFalse(\Drupal::cache('field')->get($cid), 'Cached: no cache entry on insert');
// Load, and check that a cache entry is present with the expected values.
$controller = $this->container->get('entity.manager')->getStorageController($entity->getEntityTypeId());
$controller->resetCache();
$controller->load($entity->id());
$cache = cache('field')->get($cid);
$cache = \Drupal::cache('field')->get($cid);
$this->assertEqual($cache->data[$langcode][$this->field_name_2], $values, 'Cached: correct cache entry on load');
// Update with different values, and check that the cache entry is wiped.
......@@ -231,12 +231,12 @@ function testFieldAttachCache() {
));
$entity->{$this->field_name_2} = $values;
$entity->save();
$this->assertFalse(cache('field')->get($cid), 'Cached: no cache entry on update');
$this->assertFalse(\Drupal::cache('field')->get($cid), 'Cached: no cache entry on update');
// Load, and check that a cache entry is present with the expected values.
$controller->resetCache();
$controller->load($entity->id());
$cache = cache('field')->get($cid);
$cache = \Drupal::cache('field')->get($cid);
$this->assertEqual($cache->data[$langcode][$this->field_name_2], $values, 'Cached: correct cache entry on load');
// Create a new revision, and check that the cache entry is wiped.
......@@ -248,17 +248,17 @@ function testFieldAttachCache() {
$entity->{$this->field_name_2} = $values;
$entity->setNewRevision();
$entity->save();
$this->assertFalse(cache('field')->get($cid), 'Cached: no cache entry on new revision creation');
$this->assertFalse(\Drupal::cache('field')->get($cid), 'Cached: no cache entry on new revision creation');
// Load, and check that a cache entry is present with the expected values.
$controller->resetCache();
$controller->load($entity->id());
$cache = cache('field')->get($cid);
$cache = \Drupal::cache('field')->get($cid);
$this->assertEqual($cache->data[$langcode][$this->field_name_2], $values, 'Cached: correct cache entry on load');
// Delete, and check that the cache entry is wiped.
$entity->delete();
$this->assertFalse(cache('field')->get($cid), 'Cached: no cache entry after delete');
$this->assertFalse(\Drupal::cache('field')->get($cid), 'Cached: no cache entry after delete');
}
/**
......
......@@ -421,7 +421,7 @@ function check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE,
$cache_id = '';
if ($cache) {
$cache_id = $format->format . ':' . $langcode . ':' . hash('sha256', $text);
if ($cached = cache('filter')->get($cache_id)) {
if ($cached = \Drupal::cache('filter')->get($cache_id)) {
return $cached->data;
}
}
......@@ -460,7 +460,7 @@ function check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE,
// automatically flushed when the text format is updated.
// @see \Drupal\filter\Entity\FilterFormat::save()
if ($cache) {
cache('filter')->set($cache_id, $text, Cache::PERMANENT, array('filter_format' => $format->id()));
\Drupal::cache('filter')->set($cache_id, $text, Cache::PERMANENT, array('filter_format' => $format->id()));
}
return $text;
......
......@@ -154,7 +154,7 @@ function testFilterAdmin() {
$this->drupalGet('admin/config/content/formats/manage/' . $restricted);
$this->assertFieldByName('filters[filter_html][settings][allowed_html]', $edit['filters[filter_html][settings][allowed_html]'], 'Allowed HTML tag added.');
$this->assertTrue(cache('filter')->isEmpty(), 'Cache cleared.');
$this->assertTrue(\Drupal::cache('filter')->isEmpty(), 'Cache cleared.');
$elements = $this->xpath('//select[@name=:first]/following::select[@name=:second]', array(
':first' => 'filters[' . $first_filter . '][weight]',
......
......@@ -35,7 +35,7 @@ function hook_image_effect_info_alter(&$effects) {
*/
function hook_image_style_flush($style) {
// Empty cached data that contains information about the style.
cache('mymodule')->deleteAll();
\Drupal::cache('mymodule')->deleteAll();
}
/**
......
......@@ -7,6 +7,7 @@
namespace Drupal\locale\Tests;
use Drupal\Core\Cache\Cache;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Language\Language;
use Drupal\Component\Utility\String;
......@@ -261,7 +262,7 @@ function testJavaScriptTranslation() {
// Test JavaScript translation rebuilding.
file_unmanaged_delete($js_file);
$this->assertTrue($result = !file_exists($js_file), String::format('JavaScript file deleted: %file', array('%file' => $result ? $js_file : 'found')));
cache_invalidate_tags(array('content' => TRUE));
Cache::invalidateTags(array('content' => TRUE));
_locale_rebuild_js($langcode);
$this->assertTrue($result = file_exists($js_file), String::format('JavaScript file rebuilt: %file', array('%file' => $result ? $js_file : 'not found')));
}
......
......@@ -266,7 +266,7 @@ function locale_stream_wrappers() {
function locale_language_insert($language) {
// @todo move these two cache clears out. See http://drupal.org/node/1293252
// Changing the language settings impacts the interface.
cache('page')->deleteAll();
\Drupal::cache('page')->deleteAll();
// Force JavaScript translation file re-creation for the new language.
_locale_invalidate_js($language->id);
}
......@@ -277,7 +277,7 @@ function locale_language_insert($language) {
function locale_language_update($language) {
// @todo move these two cache clears out. See http://drupal.org/node/1293252
// Changing the language settings impacts the interface.
cache('page')->deleteAll();
\Drupal::cache('page')->deleteAll();
// Force JavaScript translation file re-creation for the modified language.
_locale_invalidate_js($language->id);
}
......@@ -298,11 +298,11 @@ function locale_language_delete($language) {
// Changing the language settings impacts the interface:
_locale_invalidate_js($language->id);
cache('page')->deleteAll();
\Drupal::cache('page')->deleteAll();
// Clear locale translation caches.
locale_translation_status_delete_languages(array($language->id));
cache()->delete('locale:' . $language->id);
\Drupal::cache()->delete('locale:' . $language->id);
}
/**
......
......@@ -8,6 +8,7 @@
namespace Drupal\node;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Entity\ContentEntityFormController;
use Drupal\Core\Language\Language;
......@@ -483,7 +484,7 @@ public function save(array $form, array &$form_state) {
}
// Clear the page and block caches.
cache_invalidate_tags(array('content' => TRUE));
Cache::invalidateTags(array('content' => TRUE));
}
}
......@@ -7,6 +7,8 @@
namespace Drupal\node\Tests;
use Drupal\Core\Cache\Cache;
/**
* Functional tests for the node module blocks.
*/
......@@ -113,7 +115,7 @@ public function testRecentNodeBlock() {
$node4 = $this->drupalCreateNode($default_settings);
// drupalCreateNode() does not automatically flush content caches unlike
// posting a node from a node form.
cache_invalidate_tags(array('content' => TRUE));
Cache::invalidateTags(array('content' => TRUE));
// Test that all four nodes are shown.
$this->drupalGet('');
......
......@@ -337,7 +337,7 @@ function node_type_get_types() {