Commit bb0f5fce authored by catch's avatar catch

Issue #1194136 by Berdir, damiankloip, Wim Leers: Re-organise core cache bins.

parent d43ffb1f
......@@ -53,34 +53,20 @@ services:
factory_method: get
factory_service: cache_factory
arguments: [entity]
cache.field:
cache.render:
class: Drupal\Core\Cache\CacheBackendInterface
tags:
- { name: cache.bin }
factory_method: get
factory_service: cache_factory
arguments: [field]
cache.menu:
arguments: [render]
cache.data:
class: Drupal\Core\Cache\CacheBackendInterface
tags:
- { name: cache.bin }
factory_method: get
factory_service: cache_factory
arguments: [menu]
cache.page:
class: Drupal\Core\Cache\CacheBackendInterface
tags:
- { name: cache.bin }
factory_method: get
factory_service: cache_factory
arguments: [page]
cache.path:
class: Drupal\Core\Cache\CacheBackendInterface
tags:
- { name: cache.bin }
factory_method: get
factory_service: cache_factory
arguments: [path]
arguments: [data]
config.cachedstorage.storage:
class: Drupal\Core\Config\FileStorage
factory_class: Drupal\Core\Config\FileStorageFactory
......@@ -209,13 +195,13 @@ services:
arguments: ['@entity.manager', '@form_builder']
plugin.manager.field.field_type:
class: Drupal\Core\Field\FieldTypePluginManager
arguments: ['@container.namespaces', '@cache.field', '@language_manager', '@module_handler']
arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@module_handler']
plugin.manager.field.widget:
class: Drupal\Core\Field\WidgetPluginManager
arguments: ['@container.namespaces', '@cache.field', '@module_handler', '@language_manager', '@plugin.manager.field.field_type']
arguments: ['@container.namespaces', '@cache.cache', '@module_handler', '@language_manager', '@plugin.manager.field.field_type']
plugin.manager.field.formatter:
class: Drupal\Core\Field\FormatterPluginManager
arguments: ['@container.namespaces', '@cache.field', '@module_handler', '@language_manager', '@plugin.manager.field.field_type']
arguments: ['@container.namespaces', '@cache.cache', '@module_handler', '@language_manager', '@plugin.manager.field.field_type']
plugin.manager.archiver:
class: Drupal\Core\Archiver\ArchiverManager
parent: default_plugin_manager
......@@ -359,7 +345,7 @@ services:
- { name: event_subscriber }
path.alias_manager.cached:
class: Drupal\Core\CacheDecorator\AliasManagerCacheDecorator
arguments: ['@path.alias_manager', '@cache.path']
arguments: ['@path.alias_manager', '@cache.data']
path.crud:
class: Drupal\Core\Path\Path
arguments: ['@database', '@module_handler']
......
......@@ -654,7 +654,7 @@ function drupal_page_cache_get_cid(Request $request) {
*/
function drupal_page_get_cache(Request $request) {
if (drupal_page_is_cacheable()) {
return \Drupal::cache('page')->get(drupal_page_cache_get_cid($request));
return \Drupal::cache('render')->get(drupal_page_cache_get_cid($request));
}
}
......
......@@ -3194,7 +3194,7 @@ function drupal_page_set_cache(Response $response, Request $request) {
if ($page_compressed) {
$cache->data['body'] = gzencode($cache->data['body'], 9, FORCE_GZIP);
}
\Drupal::cache('page')->set($cache->cid, $cache->data, $cache->expire, $cache->tags);
\Drupal::cache('render')->set($cache->cid, $cache->data, $cache->expire, $cache->tags);
}
return $cache;
}
......@@ -4075,7 +4075,7 @@ function drupal_render_cache_get(array $elements) {
if (!\Drupal::request()->isMethodSafe() || !$cid = drupal_render_cid_create($elements)) {
return FALSE;
}
$bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'cache';
$bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'render';
if (!empty($cid) && $cache = \Drupal::cache($bin)->get($cid)) {
$cached_element = $cache->data;
......@@ -4133,7 +4133,7 @@ function drupal_render_cache_set(&$markup, array $elements) {
$data['#cache']['tags'] = $elements['#cache']['tags'];
}
$bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'cache';
$bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'render';
$expire = isset($elements['#cache']['expire']) ? $elements['#cache']['expire'] : Cache::PERMANENT;
\Drupal::cache($bin)->set($cid, $data, $expire, $elements['#cache']['tags']);
}
......@@ -4657,9 +4657,7 @@ function drupal_flush_all_caches() {
// sufficient, since new extensions cannot have any primed caches yet.
$module_handler->invokeAll('cache_flush');
foreach (Cache::getBins() as $service_id => $cache_backend) {
if ($service_id != 'cache.menu') {
$cache_backend->deleteAll();
}
$cache_backend->deleteAll();
}
// Flush asset file caches.
......
......@@ -444,8 +444,8 @@ function menu_tree_all_data($menu_name, $link = NULL, $max_depth = NULL) {
$cid = 'links:' . $menu_name . ':all:' . $mlid . ':' . $language_interface->id . ':' . (int) $max_depth;
if (!isset($tree[$cid])) {
// If the static variable doesn't have the data, check {cache_menu}.
$cache = \Drupal::cache('menu')->get($cid);
// If the static variable doesn't have the data, check {cache_data}.
$cache = \Drupal::cache('data')->get($cid);
if ($cache && isset($cache->data)) {
// If the cache entry exists, it contains the parameters for
// menu_build_tree().
......@@ -472,7 +472,7 @@ function menu_tree_all_data($menu_name, $link = NULL, $max_depth = NULL) {
}
// Cache the tree building parameters using the page-specific cid.
\Drupal::cache('menu')->set($cid, $tree_parameters, Cache::PERMANENT, array('menu' => $menu_name));
\Drupal::cache('data')->set($cid, $tree_parameters, Cache::PERMANENT, array('menu' => $menu_name));
}
// Build the tree using the parameters; the resulting tree will be cached
......@@ -579,8 +579,8 @@ 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 = \Drupal::cache('menu')->get($cid);
// If the static variable doesn't have the data, check {cache_data}.
$cache = \Drupal::cache('data')->get($cid);
if ($cache && isset($cache->data)) {
// If the cache entry exists, it contains the parameters for
// menu_build_tree().
......@@ -648,7 +648,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.
\Drupal::cache('menu')->set($cid, $tree_parameters, Cache::PERMANENT, array('menu' => $menu_name));
\Drupal::cache('data')->set($cid, $tree_parameters, Cache::PERMANENT, array('menu' => $menu_name));
}
// Build the tree using the parameters; the resulting tree will be cached
......@@ -714,9 +714,9 @@ function _menu_build_tree($menu_name, array $parameters = array()) {
}
$tree_cid = 'links:' . $menu_name . ':tree-data:' . $language_interface->id . ':' . hash('sha256', serialize($parameters));
// If we do not have this tree in the static cache, check {cache_menu}.
// If we do not have this tree in the static cache, check {cache_data}.
if (!isset($trees[$tree_cid])) {
$cache = \Drupal::cache('menu')->get($tree_cid);
$cache = \Drupal::cache('data')->get($tree_cid);
if ($cache && isset($cache->data)) {
$trees[$tree_cid] = $cache->data;
}
......@@ -759,7 +759,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.
\Drupal::cache('menu')->set($tree_cid, $data, Cache::PERMANENT, array('menu' => $menu_name));
\Drupal::cache('data')->set($tree_cid, $data, Cache::PERMANENT, array('menu' => $menu_name));
$trees[$tree_cid] = $data;
}
......@@ -1538,7 +1538,7 @@ function menu_get_active_trail() {
* might have been made to the router items or menu links.
*/
function menu_cache_clear_all() {
\Drupal::cache('menu')->deleteAll();
\Drupal::cache('data')->deleteAll();
menu_reset_static_cache();
}
......
......@@ -226,7 +226,7 @@ public function deleteMultiple(array $cids) {
catch (\Exception $e) {
// Create the cache table, which will be empty. This fixes cases during
// core install where a cache table is cleared before it is set
// with {cache_block} and {cache_menu}.
// with {cache_render} and {cache_data}.
if (!$this->ensureBinExists()) {
$this->catchException($e);
}
......@@ -269,7 +269,7 @@ public function deleteAll() {
catch (\Exception $e) {
// Create the cache table, which will be empty. This fixes cases during
// core install where a cache table is cleared before it is set
// with {cache_block} and {cache_menu}.
// with {cache_render} and {cache_data}.
if (!$this->ensureBinExists()) {
$this->catchException($e);
}
......
......@@ -46,12 +46,9 @@ class EntityViewBuilder extends EntityControllerBase implements EntityController
/**
* The cache bin used to store the render cache.
*
* @todo Defaults to 'cache' for now, until http://drupal.org/node/1194136 is
* fixed.
*
* @var string
*/
protected $cacheBin = 'cache';
protected $cacheBin = 'render';
/**
* The language manager.
......
......@@ -133,7 +133,7 @@ protected function loadFieldItems(array $entities) {
foreach ($entities as $id => $entity) {
$cids[] = "field:{$this->entityTypeId}:$id";
}
$cache = \Drupal::cache('field')->getMultiple($cids);
$cache = \Drupal::cache('entity')->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) {
......@@ -182,7 +182,7 @@ protected function loadFieldItems(array $entities) {
}
}
$cid = "field:{$this->entityTypeId}:$id";
\Drupal::cache('field')->set($cid, $data);
\Drupal::cache('entity')->set($cid, $data);
}
}
}
......@@ -206,7 +206,7 @@ protected function saveFieldItems(EntityInterface $entity, $update = TRUE) {
if ($update) {
$entity_type = $entity->getEntityType();
if ($entity_type->isFieldDataCacheable()) {
\Drupal::cache('field')->delete('field:' . $entity->getEntityTypeId() . ':' . $entity->id());
\Drupal::cache('entity')->delete('field:' . $entity->getEntityTypeId() . ':' . $entity->id());
}
}
}
......@@ -226,7 +226,7 @@ protected function deleteFieldItems(EntityInterface $entity) {
$entity_type = $entity->getEntityType();
if ($entity_type->isFieldDataCacheable()) {
\Drupal::cache('field')->delete('field:' . $entity->getEntityTypeId() . ':' . $entity->id());
\Drupal::cache('entity')->delete('field:' . $entity->getEntityTypeId() . ':' . $entity->id());
}
}
......
services:
plugin.manager.block:
class: Drupal\block\Plugin\Type\BlockManager
arguments: ['@container.namespaces', '@cache.block', '@language_manager', '@module_handler', '@string_translation']
cache.block:
class: Drupal\Core\Cache\CacheBackendInterface
tags:
- { name: cache.bin }
factory_method: get
factory_service: cache_factory
arguments: [block]
arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@module_handler', '@string_translation']
theme.negotiator.block.admin_demo:
class: Drupal\block\Theme\AdminDemoNegotiator
tags:
......
......@@ -287,7 +287,7 @@ public function getCacheTags() {
* {@inheritdoc}
*/
public function getCacheBin() {
return 'block';
return 'render';
}
/**
......
......@@ -279,7 +279,7 @@ public function testBlockCacheTags() {
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT');
$cid_parts = array(url('<front>', array('absolute' => TRUE)), 'html');
$cid = sha1(implode(':', $cid_parts));
$cache_entry = \Drupal::cache('page')->get($cid);
$cache_entry = \Drupal::cache('render')->get($cid);
$expected_cache_tags = array(
'content:1',
'block_view:1',
......@@ -287,7 +287,7 @@ public function testBlockCacheTags() {
'block_plugin:system_powered_by_block',
);
$this->assertIdentical($cache_entry->tags, $expected_cache_tags);
$cache_entry = \Drupal::cache('block')->get('entity_view:block:powered:en:stark');
$cache_entry = \Drupal::cache('render')->get('entity_view:block:powered:en:stark');
$this->assertIdentical($cache_entry->tags, $expected_cache_tags);
// The "Powered by Drupal" block is modified; verify a cache miss.
......@@ -310,7 +310,7 @@ public function testBlockCacheTags() {
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT');
$cid_parts = array(url('<front>', array('absolute' => TRUE)), 'html');
$cid = sha1(implode(':', $cid_parts));
$cache_entry = \Drupal::cache('page')->get($cid);
$cache_entry = \Drupal::cache('render')->get($cid);
$expected_cache_tags = array(
'content:1',
'block_view:1',
......@@ -325,7 +325,7 @@ public function testBlockCacheTags() {
'block:powered',
'block_plugin:system_powered_by_block',
);
$cache_entry = \Drupal::cache('block')->get('entity_view:block:powered:en:stark');
$cache_entry = \Drupal::cache('render')->get('entity_view:block:powered:en:stark');
$this->assertIdentical($cache_entry->tags, $expected_cache_tags);
$expected_cache_tags = array(
'content:1',
......@@ -333,7 +333,7 @@ public function testBlockCacheTags() {
'block:powered-2',
'block_plugin:system_powered_by_block',
);
$cache_entry = \Drupal::cache('block')->get('entity_view:block:powered-2:en:stark');
$cache_entry = \Drupal::cache('render')->get('entity_view:block:powered-2:en:stark');
$this->assertIdentical($cache_entry->tags, $expected_cache_tags);
// The plugin providing the "Powered by Drupal" block is modified; verify a
......
......@@ -69,7 +69,7 @@ public function setUp() {
));
$this->block->save();
$this->container->get('cache.block')->deleteAll();
$this->container->get('cache.render')->deleteAll();
}
/**
......@@ -173,19 +173,19 @@ protected function verifyRenderCacheHandling() {
$build = $this->getBlockRenderArray();
$cid = drupal_render_cid_create($build);
drupal_render($build);
$this->assertTrue($this->container->get('cache.block')->get($cid), 'The block render element has been cached.');
$this->assertTrue($this->container->get('cache.render')->get($cid), 'The block render element has been cached.');
// Re-save the block and check that the cache entry has been deleted.
$this->block->save();
$this->assertFalse($this->container->get('cache.block')->get($cid), 'The block render cache entry has been cleared when the block was saved.');
$this->assertFalse($this->container->get('cache.render')->get($cid), 'The block render cache entry has been cleared when the block was saved.');
// Rebuild the render array (creating a new cache entry in the process) and
// delete the block to check the cache entry is deleted.
unset($build['#printed']);
drupal_render($build);
$this->assertTrue($this->container->get('cache.block')->get($cid), 'The block render element has been cached.');
$this->assertTrue($this->container->get('cache.render')->get($cid), 'The block render element has been cached.');
$this->block->delete();
$this->assertFalse($this->container->get('cache.block')->get($cid), 'The block render cache entry has been cleared when the block was deleted.');
$this->assertFalse($this->container->get('cache.render')->get($cid), 'The block render cache entry has been cleared when the block was deleted.');
// Restore the previous request method.
$this->container->get('request')->setMethod($request_method);
......@@ -234,11 +234,11 @@ public function testBlockViewBuilderAlter() {
$this->assertIdentical($expected_keys, $build['#cache']['keys'], 'An altered cacheable block has the expected cache keys.');
$cid = drupal_render_cid_create(array('#cache' => array('keys' => $expected_keys)));
$this->assertIdentical(drupal_render($build), '');
$cache_entry = $this->container->get('cache.block')->get($cid);
$cache_entry = $this->container->get('cache.render')->get($cid);
$this->assertTrue($cache_entry, 'The block render element has been cached with the expected cache ID.');
$expected_flattened_tags = array('content:1', 'block_view:1', 'block:test_block', 'block_plugin:test_cache');
$this->assertIdentical($cache_entry->tags, array_combine($expected_flattened_tags, $expected_flattened_tags)); //, 'The block render element has been cached with the expected cache tags.');
$this->container->get('cache.block')->delete($cid);
$this->container->get('cache.render')->delete($cid);
// Advanced: cached block, but an alter hook adds an additional cache tag.
$alter_add_tag = $this->randomName();
......@@ -248,11 +248,11 @@ public function testBlockViewBuilderAlter() {
$this->assertIdentical($expected_tags, $build['#cache']['tags'], 'An altered cacheable block has the expected cache tags.');
$cid = drupal_render_cid_create(array('#cache' => array('keys' => $expected_keys)));
$this->assertIdentical(drupal_render($build), '');
$cache_entry = $this->container->get('cache.block')->get($cid);
$cache_entry = $this->container->get('cache.render')->get($cid);
$this->assertTrue($cache_entry, 'The block render element has been cached with the expected cache ID.');
$expected_flattened_tags = array('content:1', 'block_view:1', 'block:test_block', 'block_plugin:test_cache', $alter_add_tag . ':1');
$this->assertIdentical($cache_entry->tags, array_combine($expected_flattened_tags, $expected_flattened_tags)); //, 'The block render element has been cached with the expected cache tags.');
$this->container->get('cache.block')->delete($cid);
$this->container->get('cache.render')->delete($cid);
// Advanced: cached block, but an alter hook adds a #pre_render callback to
// alter the eventual content.
......@@ -286,7 +286,7 @@ public function testBlockViewBuilderCacheContexts() {
$build = $this->getBlockRenderArray();
$cid = drupal_render_cid_create($build);
drupal_render($build);
$this->assertTrue($this->container->get('cache.block', $cid), 'The block render element has been cached.');
$this->assertTrue($this->container->get('cache.render', $cid), 'The block render element has been cached.');
// Second: the "per URL" cache context.
$this->setBlockCacheConfig(array(
......@@ -297,7 +297,7 @@ public function testBlockViewBuilderCacheContexts() {
$build = $this->getBlockRenderArray();
$cid = drupal_render_cid_create($build);
drupal_render($build);
$this->assertTrue($this->container->get('cache.block', $cid), 'The block render element has been cached.');
$this->assertTrue($this->container->get('cache.render', $cid), 'The block render element has been cached.');
$this->assertNotEqual($cid, $old_cid, 'The cache ID has changed.');
// Third: the same block configuration, but a different URL.
......@@ -308,7 +308,7 @@ public function testBlockViewBuilderCacheContexts() {
$build = $this->getBlockRenderArray();
$cid = drupal_render_cid_create($build);
drupal_render($build);
$this->assertTrue($this->container->get('cache.block', $cid), 'The block render element has been cached.');
$this->assertTrue($this->container->get('cache.render', $cid), 'The block render element has been cached.');
$this->assertNotEqual($cid, $old_cid, 'The cache ID has changed.');
$this->container->set('cache_context.url', $original_url_cache_context);
......
......@@ -10,7 +10,7 @@
*/
function book_uninstall() {
// Clear book data out of the cache.
\Drupal::cache('menu')->deleteAll();
\Drupal::cache('data')->deleteAll();
}
/**
......
......@@ -444,7 +444,7 @@ public function deleteFromBook($nid) {
}
$this->updateOriginalParent($original);
$this->books = NULL;
\Drupal::cache('menu')->deleteTags(array('bid' => $original['bid']));
\Drupal::cache('data')->deleteTags(array('bid' => $original['bid']));
}
/**
......@@ -606,9 +606,9 @@ protected function _menu_build_tree($bid, array $parameters = array()) {
}
$tree_cid = 'book-links:' . $bid . ':tree-data:' . $language_interface->id . ':' . hash('sha256', serialize($parameters));
// If we do not have this tree in the static cache, check {cache_menu}.
// If we do not have this tree in the static cache, check {cache_data}.
if (!isset($trees[$tree_cid])) {
$cache = \Drupal::cache('menu')->get($tree_cid);
$cache = \Drupal::cache('data')->get($tree_cid);
if ($cache && isset($cache->data)) {
$trees[$tree_cid] = $cache->data;
}
......@@ -651,7 +651,7 @@ protected function _menu_build_tree($bid, array $parameters = array()) {
$this->bookTreeCollectNodeLinks($data['tree'], $data['node_links']);
// Cache the data, if it is not already in the cache.
\Drupal::cache('menu')->set($tree_cid, $data, Cache::PERMANENT, array('bid' => $bid));
\Drupal::cache('data')->set($tree_cid, $data, Cache::PERMANENT, array('bid' => $bid));
$trees[$tree_cid] = $data;
}
......@@ -744,7 +744,7 @@ public function saveBookLink(array $link, $new) {
$query->execute();
}
foreach ($affected_bids as $bid) {
\Drupal::cache('menu')->deleteTags(array('bid' => $bid));
\Drupal::cache('data')->deleteTags(array('bid' => $bid));
}
}
......@@ -1031,12 +1031,12 @@ public function bookMenuSubtreeData($link) {
$cid = 'book-links:subtree-cid:' . $link['nid'];
if (!isset($tree[$cid])) {
$cache = \Drupal::cache('menu')->get($cid);
$cache = \Drupal::cache('data')->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 = \Drupal::cache('menu')->get($cache->data);
$cache = \Drupal::cache('data')->get($cache->data);
if ($cache && isset($cache->data)) {
$data = $cache->data;
......@@ -1065,11 +1065,11 @@ public function bookMenuSubtreeData($link) {
$tree_cid = 'book-links:subtree-data:' . hash('sha256', serialize($data));
// Cache the data, if it is not already in the cache.
if (!\Drupal::cache('menu')->get($tree_cid)) {
\Drupal::cache('menu')->set($tree_cid, $data, Cache::PERMANENT, array('bid' => $link['bid']));
if (!\Drupal::cache('data')->get($tree_cid)) {
\Drupal::cache('data')->set($tree_cid, $data, Cache::PERMANENT, array('bid' => $link['bid']));
}
// Cache the cid of the (shared) data using the menu and item-specific cid.
\Drupal::cache('menu')->set($cid, $tree_cid, Cache::PERMANENT, array('bid' => $link['bid']));
\Drupal::cache('data')->set($cid, $tree_cid, Cache::PERMANENT, array('bid' => $link['bid']));
}
// Check access for the current user to each item in the tree.
$this->bookTreeCheckAccess($data['tree'], $data['node_links']);
......
......@@ -9,7 +9,6 @@
use Drupal\book\BookManagerInterface;
use Drupal\Component\Utility\Crypt;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Entity\EntityStorageControllerInterface;
use Drupal\Core\Form\FormBase;
use Drupal\node\NodeInterface;
......@@ -20,13 +19,6 @@
*/
class BookAdminEditForm extends FormBase {
/**
* The menu cache object for this controller.
*
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected $cache;
/**
* The node storage controller.
*
......@@ -44,15 +36,12 @@ class BookAdminEditForm extends FormBase {
/**
* Constructs a new BookAdminEditForm.
*
* @param \Drupal\Core\Cache\CacheBackendInterface $cache
* The menu cache object to be used by this controller.
* @param \Drupal\Core\Entity\EntityStorageControllerInterface $node_storage
* The custom block storage controller.
* @param \Drupal\book\BookManagerInterface $book_manager
* The book manager.
*/
public function __construct(CacheBackendInterface $cache, EntityStorageControllerInterface $node_storage, BookManagerInterface $book_manager) {
$this->cache = $cache;
public function __construct(EntityStorageControllerInterface $node_storage, BookManagerInterface $book_manager) {
$this->nodeStorage = $node_storage;
$this->bookManager = $book_manager;
}
......@@ -63,7 +52,6 @@ public function __construct(CacheBackendInterface $cache, EntityStorageControlle
public static function create(ContainerInterface $container) {
$entity_manager = $container->get('entity.manager');
return new static(
$container->get('cache.menu'),
$entity_manager->getStorageController('node'),
$container->get('book.manager')
);
......@@ -109,8 +97,6 @@ public function submitForm(array &$form, array &$form_state) {
$order = array_flip(array_keys($form_state['input']['table']));
$form['table'] = array_merge($order, $form['table']);
// Track updates.
$updated = FALSE;
foreach (element_children($form['table']) as $key) {
if ($form['table'][$key]['#item']) {
$row = $form['table'][$key];
......@@ -122,7 +108,6 @@ public function submitForm(array &$form, array &$form_state) {
$link['weight'] = $values['weight'];
$link['pid'] = $values['pid'];
$this->bookManager->saveBookLink($link, FALSE);
$updated = TRUE;
}
// Update the title if changed.
......@@ -137,12 +122,6 @@ public function submitForm(array &$form, array &$form_state) {
}
}
}
if ($updated) {
// Flush static and cache.
drupal_static_reset('book_menu_subtree_data');
$cid = 'book-links:subtree-cid:' . $form['#node']->book['nid'];
$this->cache->delete($cid);
}
drupal_set_message($this->t('Updated book %title.', array('%title' => $form['#node']->label())));
}
......
......@@ -143,9 +143,7 @@ public function submitForm(array &$form, array &$form_state) {
// Flush all persistent caches.
$this->moduleHandler->invokeAll('cache_flush');
foreach (Cache::getBins() as $service_id => $cache_backend) {
if ($service_id != 'cache.menu') {
$cache_backend->deleteAll();
}
$cache_backend->deleteAll();
}
drupal_set_message($this->t('@language translation of %label was deleted', array('%label' => $this->mapper->getTitle(), '@language' => $this->language->name)));
......
......@@ -259,7 +259,7 @@ function field_modules_uninstalled($modules) {
* Clears the field info and field data caches.
*/
function field_cache_clear() {
\Drupal::cache('field')->deleteAll();
\Drupal::cache('entity')->deleteAll();
field_info_cache_clear();
}
......
services:
field.info:
class: Drupal\field\FieldInfo
arguments: ['@cache.field', '@config.factory', '@module_handler', '@plugin.manager.field.field_type', '@language_manager']
arguments: ['@cache.cache', '@config.factory', '@module_handler', '@plugin.manager.field.field_type', '@language_manager']
......@@ -187,14 +187,14 @@ function testFieldAttachCache() {
$cid = "field:$entity_type:" . $entity_init->id();
// Check that no initial cache entry is present.
$this->assertFalse(\Drupal::cache('field')->get($cid), 'Non-cached: no initial cache entry');
$this->assertFalse(\Drupal::cache('entity')->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(\Drupal::cache('field')->get($cid), 'Non-cached: no cache entry on insert and load');
$this->assertFalse(\Drupal::cache('entity')->get($cid), 'Non-cached: no cache entry on insert and load');
// Cacheable entity type.
$entity_type = 'entity_test_cache';
......@@ -207,7 +207,7 @@ function testFieldAttachCache() {
// Check that no initial cache entry is present.
$cid = "field:$entity_type:" . $entity->id();
$this->assertFalse(\Drupal::cache('field')->get($cid), 'Cached: no initial cache entry');
$this->assertFalse(\Drupal::cache('entity')->get($cid), 'Cached: no initial cache entry');
// Save, and check that no cache entry is present.
$entity = clone($entity_init);
......@@ -215,12 +215,12 @@ function testFieldAttachCache() {
$entity->save();
$cid = "field:$entity_type:" . $entity->id();
$this->assertFalse(\Drupal::cache('field')->get($cid), 'Cached: no cache entry on insert');
$this->assertFalse(\Drupal::cache('entity')->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 = \Drupal::cache('field')->get($cid);
$cache = \Drupal::cache('entity')->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(\Drupal::cache('field')->get($cid), 'Cached: no cache entry on update');
$this->assertFalse(\Drupal::cache('entity')->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 = \Drupal::cache('field')->get($cid);
$cache = \Drupal::cache('entity')->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(\Drupal::cache('field')->get($cid), 'Cached: no cache entry on new revision creation');
$this->assertFalse(\Drupal::cache('entity')->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 = \Drupal::cache('field')->get($cid);
$cache = \Drupal::cache('entity')->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(\Drupal::cache('field')->get($cid), 'Cached: no cache entry after delete');
$this->assertFalse(\Drupal::cache('entity')->get($cid), 'Cached: no cache entry after delete');
}
/**
......
......@@ -259,8 +259,9 @@ public function flush($path = NULL) {
field_info_cache_clear();
drupal_theme_rebuild();
// Clear page caches when flushing.
\Drupal::cache('page')->deleteAll();
// Clear render cache when flushing.
\Drupal::cache('render')->deleteAll();
return $this;
}
......
......@@ -245,8 +245,8 @@ function locale_stream_wrappers() {
*/
function locale_language_entity_insert(LanguageEntity $language) {
// @todo move these two cache clears out. See http://drupal.org/node/1293252
// Changing the language settings impacts the interface.
\Drupal::cache('page')->deleteAll();
// Changing the language settings impacts the interface: clear render cache.