Commit 6f33b604 authored by catch's avatar catch

Issue #2124957 by Wim Leers, catch: Replace 'content' cache tag with...

Issue #2124957 by Wim Leers, catch: Replace 'content' cache tag with 'rendered' and use it sparingly.
parent 86e432e0
......@@ -3658,14 +3658,17 @@ function drupal_render_cache_set(&$markup, array $elements) {
$data['#post_render_cache'] = $elements['#post_render_cache'];
}
// Tag every render cache item with the "rendered" cache tag. This allows us
// to invalidate the entire render cache, regardless of the cache bin.
$cache_tags = $elements['#cache']['tags'] ?: array();
$cache_tags['rendered'] = TRUE;
// Persist cache tags associated with this element.
if (isset($elements['#cache']['tags'])) {
$data['#cache']['tags'] = $elements['#cache']['tags'];
}
$data['#cache']['tags'] = $cache_tags;
$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']);
\Drupal::cache($bin)->set($cid, $data, $expire, $cache_tags);
}
/**
......
......@@ -6,7 +6,6 @@
*/
use Drupal\Component\Utility\String;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Render\Element;
use Drupal\Core\Template\Attribute;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
......@@ -905,24 +904,22 @@ function menu_delete_links($menu_name) {
}
/**
* Clears the page and block caches at most twice per page load.
* Updates the expanded menu item state at most twice per page load.
*/
function _menu_clear_page_cache() {
$cache_cleared = &drupal_static(__FUNCTION__, 0);
function _menu_update_expanded_menus() {
$expanded_menus_updated = &drupal_static(__FUNCTION__, 0);
// Clear the page and block caches, but at most twice, including at
// Update the expanded menu item state, 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::invalidateTags(array('content' => TRUE));
if ($expanded_menus_updated == 0) {
// Keep track of which menus have expanded items.
_menu_set_expanded_menus();
$cache_cleared = 1;
$expanded_menus_updated = 1;
}
elseif ($cache_cleared == 1) {
drupal_register_shutdown_function('Drupal\Core\Cache\Cache::invalidateTags', array('content' => TRUE));
elseif ($expanded_menus_updated == 1) {
// Keep track of which menus have expanded items.
drupal_register_shutdown_function('_menu_set_expanded_menus');
$cache_cleared = 2;
$expanded_menus_updated = 2;
}
}
......
......@@ -74,9 +74,10 @@ protected function menuLinksRebuild() {
try {
// Ensure the menu links are up to date.
menu_link_rebuild_defaults();
// Clear the menu, page and block caches.
// Clear the menu cache.
menu_cache_clear_all();
_menu_clear_page_cache();
// Track which menu items are expanded.
_menu_update_expanded_menus();
}
catch (\Exception $e) {
$transaction->rollback();
......
......@@ -62,9 +62,9 @@ public function render(HtmlFragmentInterface $fragment, $status_code = 200) {
if ($fragment instanceof CacheableInterface) {
// Collect cache tags for all the content in all the regions on the page.
$tags = $page_array['#cache']['tags'];
// Enforce the generic "content" cache tag on all pages.
// @todo Remove the "content" cache tag. @see https://drupal.org/node/2124957
$tags['content'] = TRUE;
// Tag every render cache item with the "rendered" cache tag. This allows us
// to invalidate the entire render cache, regardless of the cache bin.
$tags['rendered'] = TRUE;
$page->setCacheTags($tags);
}
......
......@@ -9,7 +9,6 @@
use Drupal\aggregator\Plugin\ParserInterface;
use Drupal\aggregator\FeedInterface;
use Drupal\Core\Cache\Cache;
use Zend\Feed\Reader\Reader;
use Zend\Feed\Reader\Exception\ExceptionInterface;
......@@ -69,9 +68,6 @@ public function parse(FeedInterface $feed) {
$feed->items[] = $parsed_item;
}
// Clear the page and block caches.
Cache::invalidateTags(array('content' => TRUE));
return TRUE;
}
......
......@@ -7,7 +7,6 @@
namespace Drupal\block;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -177,9 +176,6 @@ public function submit(array $form, array &$form_state) {
$entity->save();
drupal_set_message($this->t('The block configuration has been saved.'));
// Invalidate the content cache and redirect to the block listing,
// because we need to remove cached block contents for each cache backend.
Cache::invalidateTags(array('content' => TRUE));
$form_state['redirect_route'] = array(
'route_name' => 'block.admin_display_theme',
'route_parameters' => array(
......
......@@ -10,7 +10,6 @@
use Drupal\block\BlockManagerInterface;
use Drupal\Component\Serialization\Json;
use Drupal\Component\Utility\String;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageInterface;
......@@ -411,8 +410,6 @@ public function submitForm(array &$form, array &$form_state) {
// Remove any previously set block placement.
$this->request->query->remove('block-placement');
Cache::invalidateTags(array('content' => TRUE));
}
}
......@@ -70,7 +70,6 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la
// Set cache tags; these always need to be set, whether the block is
// cacheable or not, so that the page cache is correctly informed.
$build[$entity_id]['#cache']['tags'] = NestedArray::mergeDeepArray(array(
array('content' => TRUE),
$this->getCacheTag(), // Block view builder cache tag.
$entity->getCacheTag(), // Block entity cache tag.
$entity->getListCacheTags(), // Block entity list cache tags.
......
......@@ -84,7 +84,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::invalidateTags(array('content' => TRUE));
Cache::invalidateTags(array('block_view' => 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.');
......
......@@ -300,19 +300,19 @@ public function testBlockCacheTags() {
$expected_cache_tags = array(
'theme:stark',
'theme_global_settings:1',
'content:1',
'block_view:1',
'block:powered',
'block_plugin:system_powered_by_block',
'rendered:1',
);
$this->assertIdentical($cache_entry->tags, $expected_cache_tags);
$cache_entry = \Drupal::cache('render')->get('entity_view:block:powered:en:stark');
$expected_cache_tags = array(
'content:1',
'block_view:1',
'block:powered',
'theme:stark',
'block_plugin:system_powered_by_block',
'rendered:1',
);
$this->assertIdentical($cache_entry->tags, $expected_cache_tags);
......@@ -340,28 +340,28 @@ public function testBlockCacheTags() {
$expected_cache_tags = array(
'theme:stark',
'theme_global_settings:1',
'content:1',
'block_view:1',
'block:powered-2',
'block:powered',
'block_plugin:system_powered_by_block',
'rendered:1',
);
$this->assertEqual($cache_entry->tags, $expected_cache_tags);
$expected_cache_tags = array(
'content:1',
'block_view:1',
'block:powered',
'theme:stark',
'block_plugin:system_powered_by_block',
'rendered:1',
);
$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',
'block_view:1',
'block:powered-2',
'theme:stark',
'block_plugin:system_powered_by_block',
'rendered:1',
);
$cache_entry = \Drupal::cache('render')->get('entity_view:block:powered-2:en:stark');
$this->assertIdentical($cache_entry->tags, $expected_cache_tags);
......
......@@ -222,7 +222,7 @@ public function testBlockViewBuilderAlter() {
$this->container->get('request')->setMethod('GET');
$default_keys = array('entity_view', 'block', 'test_block', 'en', 'cache_context.theme');
$default_tags = array('content' => TRUE, 'block_view' => TRUE, 'block' => array('test_block'), 'theme' => 'stark', 'block_plugin' => array('test_cache'));
$default_tags = array('block_view' => TRUE, 'block' => array('test_block'), 'theme' => 'stark', 'block_plugin' => array('test_cache'));
// Advanced: cached block, but an alter hook adds an additional cache key.
$this->setBlockCacheConfig(array(
......@@ -237,8 +237,8 @@ public function testBlockViewBuilderAlter() {
$this->assertIdentical(drupal_render($build), '');
$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', 'theme:stark', 'block_plugin:test_cache');
$this->assertIdentical($cache_entry->tags, $expected_flattened_tags); //, 'The block render element has been cached with the expected cache tags.');
$expected_flattened_tags = array('block_view:1', 'block:test_block', 'theme:stark', 'block_plugin:test_cache', 'rendered:1');
$this->assertIdentical($cache_entry->tags, $expected_flattened_tags, 'The block render element has been cached with the expected cache tags.');
$this->container->get('cache.render')->delete($cid);
// Advanced: cached block, but an alter hook adds an additional cache tag.
......@@ -251,8 +251,8 @@ public function testBlockViewBuilderAlter() {
$this->assertIdentical(drupal_render($build), '');
$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', 'theme:stark', 'block_plugin:test_cache', $alter_add_tag . ':1');
$this->assertIdentical($cache_entry->tags, $expected_flattened_tags); //, 'The block render element has been cached with the expected cache tags.');
$expected_flattened_tags = array('block_view:1', 'block:test_block', 'theme:stark', 'block_plugin:test_cache', $alter_add_tag . ':1', 'rendered:1');
$this->assertIdentical($cache_entry->tags, $expected_flattened_tags, 'The block render element has been cached with the expected cache tags.');
$this->container->get('cache.render')->delete($cid);
// Advanced: cached block, but an alter hook adds a #pre_render callback to
......
......@@ -7,7 +7,6 @@
namespace Drupal\block_content;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityStorageInterface;
......@@ -232,9 +231,6 @@ public function save(array $form, array &$form_state) {
drupal_set_message($this->t('The block could not be saved.'), 'error');
$form_state['rebuild'] = TRUE;
}
// Clear the page and block caches.
Cache::invalidateTags(array('content' => TRUE));
}
/**
......
......@@ -10,7 +10,6 @@
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Entity\EntityManagerInterface;
......@@ -411,9 +410,5 @@ public function save(array $form, array &$form_state) {
// Redirect the user to the entity they are commenting on.
}
$form_state['redirect_route'] = $uri;
// Clear the block and page caches so that anonymous users see the comment
// they have posted.
Cache::invalidateTags(array('content' => TRUE));
$this->entityManager->getViewBuilder($entity->getEntityTypeId())->resetCache(array($entity));
}
}
......@@ -10,7 +10,6 @@
use Drupal\comment\CommentInterface;
use Drupal\comment\CommentStorageInterface;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Datetime\Date;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
......@@ -284,7 +283,6 @@ public function submitForm(array &$form, array &$form_state) {
$form_state['redirect_route'] = array(
'route_name' => 'comment.admin',
);
Cache::invalidateTags(array('content' => TRUE));
}
}
......@@ -9,7 +9,6 @@
use Drupal\comment\CommentStorageInterface;
use Drupal\Component\Utility\String;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -120,7 +119,6 @@ public function buildForm(array $form, array &$form_state) {
public function submitForm(array &$form, array &$form_state) {
if ($form_state['values']['confirm']) {
$this->commentStorage->delete($this->comments);
Cache::invalidateTags(array('content' => TRUE));
$count = count($form_state['values']['comments']);
watchdog('content', 'Deleted @count comments.', array('@count' => $count));
drupal_set_message(format_plural($count, 'Deleted 1 comment.', 'Deleted @count comments.'));
......
......@@ -7,7 +7,6 @@
namespace Drupal\comment\Form;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\ContentEntityConfirmFormBase;
/**
......@@ -52,8 +51,6 @@ public function submit(array $form, array &$form_state) {
$this->entity->delete();
drupal_set_message($this->t('The comment and all its replies have been deleted.'));
watchdog('content', 'Deleted comment @cid and its replies.', array('@cid' => $this->entity->id()));
// Clear the cache so an anonymous user sees that his comment was deleted.
Cache::invalidateTags(array('content' => TRUE));
$form_state['redirect_route'] = $this->getCancelRoute();
}
......
......@@ -7,7 +7,6 @@
namespace Drupal\comment\Plugin\Action;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Action\ActionBase;
/**
......@@ -26,7 +25,6 @@ class SaveComment extends ActionBase {
*/
public function execute($comment = NULL) {
$comment->save();
Cache::invalidateTags(array('content' => TRUE));
}
}
......@@ -7,7 +7,6 @@
namespace Drupal\comment\Tests;
use Drupal\Component\Utility\String;
use Drupal\Core\Cache\Cache;
/**
* Tests the Comment module blocks.
......@@ -65,9 +64,6 @@ function testRecentCommentBlock() {
// block.
$this->drupalLogout();
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::invalidateTags(array('content' => TRUE));
$this->drupalGet('');
$this->assertNoText(t('Recent comments'));
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access comments'));
......
......@@ -7,7 +7,6 @@
namespace Drupal\forum\Form;
use Drupal\Core\Cache\Cache;
use Drupal\taxonomy\TermForm;
/**
......@@ -89,8 +88,6 @@ public function save(array $form, array &$form_state) {
case SAVED_UPDATED:
drupal_set_message($this->t('The @type %term has been updated.', array('%term' => $term->getName(), '@type' => $this->forumFormType)));
watchdog('taxonomy', 'Updated @type %term.', array('%term' => $term->getName(), '@type' => $this->forumFormType), WATCHDOG_NOTICE, l($this->t('Edit'), 'admin/structure/forum/edit/' . $this->urlStub . '/' . $term->id()));
// Clear the page and block caches to avoid stale data.
Cache::invalidateTags(array('content' => TRUE));
break;
}
......
......@@ -7,7 +7,6 @@
namespace Drupal\locale\Tests;
use Drupal\Core\Cache\Cache;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Language\Language;
use Drupal\Core\Language\LanguageInterface;
......@@ -263,7 +262,6 @@ 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::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')));
}
......
......@@ -463,7 +463,7 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti
// Also clear the menu system static caches.
menu_reset_static_cache();
_menu_clear_page_cache();
_menu_update_expanded_menus();
}
/**
......@@ -556,8 +556,8 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) {
// Also clear the menu system static caches.
menu_reset_static_cache();
// Now clear the cache.
_menu_clear_page_cache();
// Track which menu items are expanded.
_menu_update_expanded_menus();
}
/**
......
......@@ -61,7 +61,7 @@ public function testMenuBlock() {
$expected_tags = array(
'theme:stark',
'theme_global_settings:1',
'content:1',
'rendered:1',
'block_view:1',
'block:' . $block->id(),
'block_plugin:system_menu_block__llama',
......@@ -119,7 +119,7 @@ public function testMenuBlock() {
$this->verifyPageCache($path, 'MISS');
// Verify a cache hit.
$this->verifyPageCache($path, 'HIT', array('content:1', 'theme:stark', 'theme_global_settings:1'));
$this->verifyPageCache($path, 'HIT', array('rendered:1', 'theme:stark', 'theme_global_settings:1'));
}
}
......@@ -14,7 +14,6 @@
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Database\Query\AlterableInterface;
use Drupal\Core\Database\Query\SelectInterface;
use Drupal\field\Entity\FieldConfig;
......@@ -1496,7 +1495,6 @@ function node_access_rebuild($batch_mode = FALSE) {
if (!isset($batch)) {
drupal_set_message(t('Content permissions have been rebuilt.'));
node_access_needs_rebuild(FALSE);
Cache::invalidateTags(array('content' => TRUE));
}
}
......@@ -1560,7 +1558,6 @@ function _node_access_rebuild_batch_finished($success, $results, $operations) {
else {
drupal_set_message(t('The content access permissions have not been properly rebuilt.'), 'error');
}
Cache::invalidateTags(array('content' => TRUE));
}
/**
......
......@@ -7,7 +7,6 @@
namespace Drupal\node\Form;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Component\Utility\String;
......@@ -123,7 +122,6 @@ public function submitForm(array &$form, array &$form_state) {
$count = count($this->nodes);
watchdog('content', 'Deleted @count posts.', array('@count' => $count));
drupal_set_message(format_plural($count, 'Deleted 1 post.', 'Deleted @count posts.'));
Cache::invalidateTags(array('content' => TRUE));
}
$form_state['redirect_route']['route_name'] = 'system.admin_content';
}
......
......@@ -7,7 +7,6 @@
namespace Drupal\node\Form;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\ContentEntityConfirmFormBase;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Routing\UrlGeneratorInterface;
......@@ -78,7 +77,6 @@ public function submit(array $form, array &$form_state) {
$node_type_storage = $this->entityManager->getStorage('node_type');
$node_type = $node_type_storage->load($this->entity->bundle())->label();
drupal_set_message(t('@type %title has been deleted.', array('@type' => $node_type, '%title' => $this->entity->label())));
Cache::invalidateTags(array('content' => TRUE));
$form_state['redirect_route']['route_name'] = '<front>';
}
......
......@@ -8,7 +8,6 @@
namespace Drupal\node;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Language\LanguageInterface;
......@@ -468,9 +467,6 @@ public function save(array $form, array &$form_state) {
drupal_set_message(t('The post could not be saved.'), 'error');
$form_state['rebuild'] = TRUE;
}
// Clear the page and block caches.
Cache::invalidateTags(array('content' => TRUE));
}
}
......@@ -9,7 +9,6 @@
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\system\Plugin\views\field\BulkForm;
use Drupal\Core\Cache\Cache;
/**
* Defines a node operations bulk form element.
......@@ -18,17 +17,6 @@
*/
class NodeBulkForm extends BulkForm {
/**
* {@inheritdoc}
*/
public function viewsFormSubmit(&$form, &$form_state) {
parent::viewsFormSubmit($form, $form_state);
if ($form_state['step'] == 'views_form_views_form') {
Cache::invalidateTags(array('content' => TRUE));
}
}
/**
* {@inheritdoc}
*/
......
......@@ -7,8 +7,6 @@
namespace Drupal\node\Tests;
use Drupal\Core\Cache\Cache;
/**
* Functional tests for the node module blocks.
*/
......@@ -113,9 +111,6 @@ public function testRecentNodeBlock() {
// Post an additional node.
$node4 = $this->drupalCreateNode($default_settings);
// drupalCreateNode() does not automatically flush content caches unlike
// posting a node from a node form.
Cache::invalidateTags(array('content' => TRUE));
// Test that all four nodes are shown.
$this->drupalGet('');
......
......@@ -427,9 +427,6 @@ public function submitForm(array &$form, array &$form_state) {
else {
Cache::invalidateTags(array('theme_global_settings' => TRUE));
}
// @todo Remove this in https://drupal.org/node/2124957.
Cache::invalidateTags(array('content' => TRUE));
}
/**
......
......@@ -67,8 +67,8 @@ function testPageCacheTags() {
$cache_entry = \Drupal::cache('render')->get($cid);
sort($cache_entry->tags);
$expected_tags = array(
'content:1',
'pre_render:1',
'rendered:1',
'system_test_cache_tags_page:1',
'theme:stark',
'theme_global_settings:1',
......
......@@ -75,7 +75,7 @@ function testPageCacheTags() {
// Full node page 1.
$this->verifyPageCacheTags('node/' . $node_1->id(), array(
'content:1',
'rendered:1',
'theme:bartik',
'theme_global_settings:1',
'block_view:1',
......@@ -100,7 +100,7 @@ function testPageCacheTags() {
// Full node page 2.
$this->verifyPageCacheTags('node/' . $node_2->id(), array(
'content:1',
'rendered:1',
'theme:bartik',
'theme_global_settings:1',
'block_view:1',
......
......@@ -500,7 +500,7 @@ function testDrupalRenderPostRenderCache() {
'#markup' => '<p>#cache enabled, GET</p>',
'#attached' => $test_element['#attached'],
'#post_render_cache' => $test_element['#post_render_cache'],
'#cache' => array('tags' => array()),
'#cache' => array('tags' => array('rendered' => TRUE)),
);
$this->assertIdentical($cached_element, $expected_element, 'The correct data is cached: the stored #markup and #attached properties are not affected by #post_render_cache callbacks.');
......@@ -617,7 +617,7 @@ function testDrupalRenderChildrenPostRenderCache() {
$context_3,
)
),
'#cache' => array('tags' => array()),
'#cache' => array('tags' => array('rendered' => TRUE)),
);
$dom = Html::load($cached_element['#markup']);
......@@ -698,7 +698,7 @@ function testDrupalRenderChildrenPostRenderCache() {
$context_3,
)
),
'#cache' => array('tags' => array()),
'#cache' => array('tags' => array('rendered' => TRUE)),
);
$dom = Html::load($cached_parent_element['#markup']);
......@@ -724,7 +724,7 @@ function testDrupalRenderChildrenPostRenderCache() {
$context_3,
)
),
'#cache' => array('tags' => array()),
'#cache' => array('tags' => array('rendered' => TRUE)),
);
$dom = Html::load($cached_child_element['#markup']);
......@@ -833,7 +833,7 @@ function testDrupalRenderRenderCachePlaceholder() {
$context
),
),
'#cache' => array('tags' => array()),
'#cache' => array('tags' => array('rendered' => TRUE)),
);
$this->assertIdentical($cached_element, $expected_element, 'The correct data is cached: the stored #markup and #attached properties are not affected by #post_render_cache callbacks.');
......@@ -931,7 +931,7 @@ function testDrupalRenderChildElementRenderCachePlaceholder() {
$context,
),
),
'#cache' => array('tags' => array()),
'#cache' => array('tags' => array('rendered' => TRUE)),
);
$this->assertIdentical($cached_element, $expected_element, 'The correct data is cached for the child element: the stored #markup and #attached properties are not affected by #post_render_cache callbacks.');
......@@ -956,7 +956,7 @@ function testDrupalRenderChildElementRenderCachePlaceholder() {
$context,
),
),
'#cache' => array('tags' => array()),
'#cache' => array('tags' => array('rendered' => TRUE)),
);
$this->assertIdentical($cached_element, $expected_element, 'The correct data is cached for the parent element: the stored #markup and #attached properties are not affected by #post_render_cache callbacks.');
......@@ -985,7 +985,7 @@ function testDrupalRenderChildElementRenderCachePlaceholder() {
$context,
),
),
'#cache' => array('tags' => array()),
'#cache' => array('tags' => array('rendered' => TRUE)),
);
$this->assertIdentical($cached_element, $expected_element, 'The correct data is cached for the child element: the stored #markup and #attached properties are not affected by #post_render_cache callbacks.');
......
......@@ -229,7 +229,8 @@ public function testReferencedEntity() {
$non_referencing_entity_path = $this->non_referencing_entity->getSystemPath();
$listing_path = 'entity_test/list/' . $entity_type . '_reference/' . $entity_type . '/' . $this->entity->id();
$theme_cache_tags = array('content:1', 'theme:stark', 'theme_global_settings:1');
$render_cache_tags = array('rendered:1');
$theme_cache_tags = array('theme:stark', 'theme_global_settings:1');
$view_cache_tag = array();
if ($this->entity->getEntityType()->hasControllerClass('view_builder')) {
......@@ -254,35 +255,32 @@ public function testReferencedEntity() {
$non_referencing_entity_cache_tags = explode(' ', HtmlViewSubscriber::convertCacheTagsToHeader($non_referencing_entity_cache_tags));
// Prime the page cache for the referencing entity.
$this->pass("Test referencing entity.", 'Debug');
$this->verifyPageCache($referencing_entity_path, 'MISS');
// Verify a cache hit, but also the presence of the correct cache tags.
$tags = array_merge($theme_cache_tags, $referencing_entity_cache_tags);
$tags = array_merge($render_cache_tags, $theme_cache_tags, $referencing_entity_cache_tags);
$this->verifyPageCache($referencing_entity_path, 'HIT', $tags);
// Also verify the existence of an entity render cache entry.
$cid = 'entity_view:entity_test:' . $this->referencing_entity->id() . ':full:stark:r.anonymous:' . date_default_timezone_get();
$this->verifyRenderCache($cid, $referencing_entity_cache_tags);
$tags = array_merge($render_cache_tags, $referencing_entity_cache_tags);
$this->verifyRenderCache($cid, $tags);
// Prime the page cache for the non-referencing entity.
$this->pass("Test non-referencing entity.", 'Debug');
$this->verifyPageCache($non_referencing_entity_path, 'MISS');
// Verify a cache hit, but also the presence of the correct cache tags.
$tags = array_merge($theme_cache_tags, $non_referencing_entity_cache_tags);
$tags = array_merge($render_cache_tags, $theme_cache_tags, $non_referencing_entity_cache_tags);