diff --git a/core/modules/aggregator/config/optional/views.view.aggregator_sources.yml b/core/modules/aggregator/config/optional/views.view.aggregator_sources.yml index bb0f0ab5a43929331759ae6a920e97784ab2504d..1a823a3b579d94628d32c71a7546532894efed8e 100644 --- a/core/modules/aggregator/config/optional/views.view.aggregator_sources.yml +++ b/core/modules/aggregator/config/optional/views.view.aggregator_sources.yml @@ -143,7 +143,7 @@ display: - 'languages:language_interface' - url.query_args - user.permissions - cacheable: false + max-age: 0 feed_1: display_plugin: feed id: feed_1 @@ -401,7 +401,7 @@ display: - 'languages:language_content' - 'languages:language_interface' - user.permissions - cacheable: false + max-age: 0 page_1: display_plugin: page id: page_1 @@ -423,4 +423,4 @@ display: - 'languages:language_interface' - url.query_args - user.permissions - cacheable: false + max-age: 0 diff --git a/core/modules/block_content/config/optional/views.view.block_content.yml b/core/modules/block_content/config/optional/views.view.block_content.yml index 27ecb0cb96663d8874dec38db0a67a26c7b4c4fe..39b8f79d5e47c84ea2b5b2f144f6cbc0b692d04d 100644 --- a/core/modules/block_content/config/optional/views.view.block_content.yml +++ b/core/modules/block_content/config/optional/views.view.block_content.yml @@ -468,7 +468,8 @@ display: - url - url.query_args - user.permissions - cacheable: false + max-age: 0 + tags: { } page_1: display_plugin: page id: page_1 @@ -492,4 +493,5 @@ display: - url - url.query_args - user.permissions - cacheable: false + max-age: 0 + tags: { } diff --git a/core/modules/comment/config/optional/views.view.comments_recent.yml b/core/modules/comment/config/optional/views.view.comments_recent.yml index 9688145919a93608d7cec05d6af59f6b0637be49..5b83bfb8188ffa5c30db40d561011e0bd6e9bb95 100644 --- a/core/modules/comment/config/optional/views.view.comments_recent.yml +++ b/core/modules/comment/config/optional/views.view.comments_recent.yml @@ -3,6 +3,7 @@ status: true dependencies: module: - comment + - node - user id: comments_recent label: 'Recent comments' @@ -241,7 +242,8 @@ display: - 'languages:language_content' - 'languages:language_interface' - user.permissions - cacheable: false + max-age: -1 + tags: { } block_1: display_plugin: block id: block_1 @@ -258,4 +260,5 @@ display: - 'languages:language_content' - 'languages:language_interface' - user.permissions - cacheable: false + max-age: -1 + tags: { } diff --git a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_field_name.yml b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_field_name.yml index 9938a658ee70119afba34d23d29fe4e1b1b94fbe..c39e6db6408bc313ff53725ec6566b4e4a2390f3 100644 --- a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_field_name.yml +++ b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_field_name.yml @@ -200,4 +200,4 @@ display: contexts: - languages - user - cacheable: false + max-age: 0 diff --git a/core/modules/contact/tests/modules/contact_test_views/test_views/views.view.test_contact_link.yml b/core/modules/contact/tests/modules/contact_test_views/test_views/views.view.test_contact_link.yml index 84b2a2b28550d24055b7335982bb1f08c0f3dd6f..b23778f7abe8ef170dd8dffb5b15da0fe015f83d 100644 --- a/core/modules/contact/tests/modules/contact_test_views/test_views/views.view.test_contact_link.yml +++ b/core/modules/contact/tests/modules/contact_test_views/test_views/views.view.test_contact_link.yml @@ -133,7 +133,7 @@ display: contexts: - 'languages:language_content' - 'languages:language_interface' - cacheable: false + max-age: 0 page_1: display_plugin: page id: page_1 @@ -146,4 +146,4 @@ display: contexts: - 'languages:language_content' - 'languages:language_interface' - cacheable: false + max-age: 0 diff --git a/core/modules/entity_reference/tests/modules/entity_reference_test_views/test_views/views.view.test_entity_reference_entity_test_mul_view.yml b/core/modules/entity_reference/tests/modules/entity_reference_test_views/test_views/views.view.test_entity_reference_entity_test_mul_view.yml index 489ea04e9fa9f2f22521bdb7b68bce536e4e1371..ee7f60e47e409fe4c9eed2713b6674233a7674a5 100644 --- a/core/modules/entity_reference/tests/modules/entity_reference_test_views/test_views/views.view.test_entity_reference_entity_test_mul_view.yml +++ b/core/modules/entity_reference/tests/modules/entity_reference_test_views/test_views/views.view.test_entity_reference_entity_test_mul_view.yml @@ -117,4 +117,4 @@ display: contexts: - languages - 'languages:language_interface' - cacheable: false + max-age: 0 diff --git a/core/modules/entity_reference/tests/modules/entity_reference_test_views/test_views/views.view.test_entity_reference_entity_test_view.yml b/core/modules/entity_reference/tests/modules/entity_reference_test_views/test_views/views.view.test_entity_reference_entity_test_view.yml index 291b474cecf779f4fc790691a49103fe373d1029..54ffdcbf3492b572b1bc18d3843c353053a908e7 100644 --- a/core/modules/entity_reference/tests/modules/entity_reference_test_views/test_views/views.view.test_entity_reference_entity_test_view.yml +++ b/core/modules/entity_reference/tests/modules/entity_reference_test_views/test_views/views.view.test_entity_reference_entity_test_view.yml @@ -118,4 +118,4 @@ display: - entity_test_view_grants - languages - 'languages:language_interface' - cacheable: false + max-age: 0 diff --git a/core/modules/entity_reference/tests/modules/entity_reference_test_views/test_views/views.view.test_entity_reference_reverse_entity_test_mul_view.yml b/core/modules/entity_reference/tests/modules/entity_reference_test_views/test_views/views.view.test_entity_reference_reverse_entity_test_mul_view.yml index 33911a65773f25cc20d368abfaffcc94e6e7dee3..e9d1b61f7ffe693bc51a7497debf435fe5c2dbcc 100644 --- a/core/modules/entity_reference/tests/modules/entity_reference_test_views/test_views/views.view.test_entity_reference_reverse_entity_test_mul_view.yml +++ b/core/modules/entity_reference/tests/modules/entity_reference_test_views/test_views/views.view.test_entity_reference_reverse_entity_test_mul_view.yml @@ -127,4 +127,4 @@ display: - entity_test_view_grants - languages - 'languages:language_interface' - cacheable: false + max-age: 0 diff --git a/core/modules/entity_reference/tests/modules/entity_reference_test_views/test_views/views.view.test_entity_reference_reverse_entity_test_view.yml b/core/modules/entity_reference/tests/modules/entity_reference_test_views/test_views/views.view.test_entity_reference_reverse_entity_test_view.yml index c281ef5c6d0f90b6f9297556c5fccad8a4011e8a..3e05f777282e88252a8469889b5279b010d3e73a 100644 --- a/core/modules/entity_reference/tests/modules/entity_reference_test_views/test_views/views.view.test_entity_reference_reverse_entity_test_view.yml +++ b/core/modules/entity_reference/tests/modules/entity_reference_test_views/test_views/views.view.test_entity_reference_reverse_entity_test_view.yml @@ -126,4 +126,4 @@ display: contexts: - languages - 'languages:language_interface' - cacheable: false + max-age: 0 diff --git a/core/modules/file/config/optional/views.view.files.yml b/core/modules/file/config/optional/views.view.files.yml index 869b7768f78cf60f522b7fefa24ba120fa90cf00..ae37f2dac11375de1545d31617ee636a761819f2 100644 --- a/core/modules/file/config/optional/views.view.files.yml +++ b/core/modules/file/config/optional/views.view.files.yml @@ -723,7 +723,8 @@ display: - url - url.query_args - user.permissions - cacheable: false + max-age: 0 + tags: { } page_1: display_plugin: page id: page_1 @@ -759,7 +760,8 @@ display: - url - url.query_args - user.permissions - cacheable: false + max-age: 0 + tags: { } page_2: display_plugin: page id: page_2 @@ -1115,4 +1117,5 @@ display: - url - url.query_args - user.permissions - cacheable: false + max-age: 0 + tags: { } diff --git a/core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php b/core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php index 4117ec0eb02c0bb0fe2fe903a914be480a5d07fe..22169273257b818bd31e363d8eda6af665ff4f5d 100644 --- a/core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php +++ b/core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php @@ -102,9 +102,9 @@ public function adminSummary() { /** * {@inheritdoc} */ - public function isCacheable() { + public function getCacheMaxAge() { // This filter depends on the current time and therefore is never cacheable. - return FALSE; + return 0; } } diff --git a/core/modules/node/config/optional/views.view.archive.yml b/core/modules/node/config/optional/views.view.archive.yml index c201e02b322535db8d7f266557f8f1b886957351..65420ad045f225e17c22773f124b39498c799af0 100644 --- a/core/modules/node/config/optional/views.view.archive.yml +++ b/core/modules/node/config/optional/views.view.archive.yml @@ -1,8 +1,11 @@ langcode: en status: false dependencies: + config: + - core.entity_view_mode.node.teaser module: - node + - user id: archive label: Archive module: node @@ -174,7 +177,8 @@ display: - url.query_args - 'user.node_grants:view' - user.permissions - cacheable: false + max-age: -1 + tags: { } block_1: id: block_1 display_title: Block @@ -212,7 +216,8 @@ display: - url.query_args - 'user.node_grants:view' - user.permissions - cacheable: false + max-age: -1 + tags: { } page_1: id: page_1 display_title: Page @@ -231,4 +236,5 @@ display: - url.query_args - 'user.node_grants:view' - user.permissions - cacheable: false + max-age: -1 + tags: { } diff --git a/core/modules/node/config/optional/views.view.content.yml b/core/modules/node/config/optional/views.view.content.yml index 78b080d8dca0e5e6aa1b76497ae3a704041641ae..96a16d57b3772e461648220504912ad4b01e3d78 100644 --- a/core/modules/node/config/optional/views.view.content.yml +++ b/core/modules/node/config/optional/views.view.content.yml @@ -568,7 +568,8 @@ display: - user - 'user.node_grants:view' - user.permissions - cacheable: false + max-age: 0 + tags: { } page_1: display_options: path: admin/content/node @@ -599,4 +600,5 @@ display: - user - 'user.node_grants:view' - user.permissions - cacheable: false + max-age: 0 + tags: { } diff --git a/core/modules/node/config/optional/views.view.content_recent.yml b/core/modules/node/config/optional/views.view.content_recent.yml index 56a425c670d1dba3d3ed6d18ab635a542a3c583b..39f4ecbad61508e54b9e549b9ee38418ff352c53 100644 --- a/core/modules/node/config/optional/views.view.content_recent.yml +++ b/core/modules/node/config/optional/views.view.content_recent.yml @@ -296,7 +296,8 @@ display: - user - 'user.node_grants:view' - user.permissions - cacheable: false + max-age: 0 + tags: { } block_1: display_plugin: block id: block_1 @@ -311,4 +312,5 @@ display: - user - 'user.node_grants:view' - user.permissions - cacheable: false + max-age: 0 + tags: { } diff --git a/core/modules/node/config/optional/views.view.frontpage.yml b/core/modules/node/config/optional/views.view.frontpage.yml index 09e1d1ba7f1bbe9a789704cf2d84252a06e7a872..3f32af50d0fb8500a5cd1e71f418226d536460e8 100644 --- a/core/modules/node/config/optional/views.view.frontpage.yml +++ b/core/modules/node/config/optional/views.view.frontpage.yml @@ -1,6 +1,9 @@ langcode: en status: true dependencies: + config: + - core.entity_view_mode.node.rss + - core.entity_view_mode.node.teaser module: - node - user @@ -244,7 +247,8 @@ display: - url.query_args - 'user.node_grants:view' - user.permissions - cacheable: false + max-age: -1 + tags: { } feed_1: display_plugin: feed id: feed_1 @@ -278,7 +282,8 @@ display: - 'languages:language_interface' - 'user.node_grants:view' - user.permissions - cacheable: false + max-age: -1 + tags: { } page_1: display_options: path: node @@ -293,4 +298,5 @@ display: - url.query_args - 'user.node_grants:view' - user.permissions - cacheable: false + max-age: -1 + tags: { } diff --git a/core/modules/node/config/optional/views.view.glossary.yml b/core/modules/node/config/optional/views.view.glossary.yml index 611947e48a7eccf3712b881617e9de4c72843366..2b4e3301004726295f42c63eeb466898e3e9ee38 100644 --- a/core/modules/node/config/optional/views.view.glossary.yml +++ b/core/modules/node/config/optional/views.view.glossary.yml @@ -355,7 +355,8 @@ display: - url.query_args - 'user.node_grants:view' - user.permissions - cacheable: false + max-age: 0 + tags: { } attachment_1: id: attachment_1 display_title: Attachment @@ -422,7 +423,8 @@ display: - url.query_args - 'user.node_grants:view' - user.permissions - cacheable: false + max-age: 0 + tags: { } page_1: id: page_1 display_title: Page @@ -448,4 +450,5 @@ display: - url.query_args - 'user.node_grants:view' - user.permissions - cacheable: false + max-age: 0 + tags: { } diff --git a/core/modules/node/src/Plugin/views/argument_default/Node.php b/core/modules/node/src/Plugin/views/argument_default/Node.php index 556b9aa95b3d30fa465d3fe20542f37b19c99145..6ed43ec371b7d188e012625e2f18fcbb20955868 100644 --- a/core/modules/node/src/Plugin/views/argument_default/Node.php +++ b/core/modules/node/src/Plugin/views/argument_default/Node.php @@ -7,8 +7,9 @@ namespace Drupal\node\Plugin\views\argument_default; +use Drupal\Core\Cache\Cache; +use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Routing\RouteMatchInterface; -use Drupal\views\Plugin\CacheablePluginInterface; use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase; use Drupal\node\NodeInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -23,7 +24,7 @@ * title = @Translation("Content ID from URL") * ) */ -class Node extends ArgumentDefaultPluginBase implements CacheablePluginInterface { +class Node extends ArgumentDefaultPluginBase implements CacheableDependencyInterface { /** * The route match. @@ -75,8 +76,8 @@ public function getArgument() { /** * {@inheritdoc} */ - public function isCacheable() { - return TRUE; + public function getCacheMaxAge() { + return Cache::PERMANENT; } /** diff --git a/core/modules/rest/src/Plugin/views/style/Serializer.php b/core/modules/rest/src/Plugin/views/style/Serializer.php index f83d57fc0ae2270a7c0a55968219b8d0e42b254b..895f00cfb44faa971e979d50f4973d9f65a6cb9c 100644 --- a/core/modules/rest/src/Plugin/views/style/Serializer.php +++ b/core/modules/rest/src/Plugin/views/style/Serializer.php @@ -7,8 +7,9 @@ namespace Drupal\rest\Plugin\views\style; +use Drupal\Core\Cache\Cache; +use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\views\Plugin\CacheablePluginInterface; use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\style\StylePluginBase; @@ -27,7 +28,7 @@ * display_types = {"data"} * ) */ -class Serializer extends StylePluginBase implements CacheablePluginInterface { +class Serializer extends StylePluginBase implements CacheableDependencyInterface { /** * Overrides \Drupal\views\Plugin\views\style\StylePluginBase::$usesRowPlugin. @@ -155,8 +156,8 @@ public function getFormats() { /** * {@inheritdoc} */ - public function isCacheable() { - return TRUE; + public function getCacheMaxAge() { + return Cache::PERMANENT; } /** @@ -166,4 +167,11 @@ public function getCacheContexts() { return ['request_format']; } + /** + * {@inheritdoc} + */ + public function getCacheTags() { + return []; + } + } diff --git a/core/modules/system/src/Plugin/views/field/BulkForm.php b/core/modules/system/src/Plugin/views/field/BulkForm.php index 609d4c02db2ed366c1733d3cc950cb6f8b7314a5..3a3b65cb6d9fb84f6dec841f23e3a9eb1a8a7b3d 100644 --- a/core/modules/system/src/Plugin/views/field/BulkForm.php +++ b/core/modules/system/src/Plugin/views/field/BulkForm.php @@ -7,6 +7,7 @@ namespace Drupal\system\Plugin\views\field; +use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\RevisionableInterface; @@ -15,7 +16,6 @@ use Drupal\Core\Routing\RedirectDestinationTrait; use Drupal\Core\TypedData\TranslatableInterface; use Drupal\views\Entity\Render\EntityTranslationRenderTrait; -use Drupal\views\Plugin\CacheablePluginInterface; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\field\FieldPluginBase; use Drupal\views\Plugin\views\field\UncacheableFieldHandlerTrait; @@ -29,7 +29,7 @@ * * @ViewsField("bulk_form") */ -class BulkForm extends FieldPluginBase implements CacheablePluginInterface { +class BulkForm extends FieldPluginBase implements CacheableDependencyInterface { use RedirectDestinationTrait; use UncacheableFieldHandlerTrait; @@ -114,10 +114,10 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o /** * {@inheritdoc} */ - public function isCacheable() { + public function getCacheMaxAge() { // @todo Consider making the bulk operation form cacheable. See // https://www.drupal.org/node/2503009. - return FALSE; + return 0; } /** @@ -127,6 +127,13 @@ public function getCacheContexts() { return $this->languageManager->isMultilingual() ? $this->getEntityTranslationRenderer()->getCacheContexts() : []; } + /** + * {@inheritdoc} + */ + public function getCacheTags() { + return []; + } + /** * {@inheritdoc} */ diff --git a/core/modules/system/src/Tests/Update/UpdatePostUpdateTest.php b/core/modules/system/src/Tests/Update/UpdatePostUpdateTest.php index 3431515ac1d63228099aa9373316de5d3d6afb12..cc34f0bd2ec504ba49559e56c923564613eee72a 100644 --- a/core/modules/system/src/Tests/Update/UpdatePostUpdateTest.php +++ b/core/modules/system/src/Tests/Update/UpdatePostUpdateTest.php @@ -59,6 +59,7 @@ public function testPostUpdate() { $this->assertIdentical($updates, \Drupal::state()->get('post_update_test_execution', [])); $key_value = \Drupal::keyValue('post_update'); + array_unshift($updates, 'views_post_update_update_cacheability_metadata'); array_unshift($updates, 'block_post_update_disable_blocks_with_missing_contexts'); $this->assertEqual($updates, $key_value->get('existing_updates')); diff --git a/core/modules/taxonomy/config/optional/views.view.taxonomy_term.yml b/core/modules/taxonomy/config/optional/views.view.taxonomy_term.yml index 23c8a4d153d870dcff1d90ccdae1afcc1ab767b9..21097a0883d5a68cd2b45ea7e1e9ce5cd8d1d228 100644 --- a/core/modules/taxonomy/config/optional/views.view.taxonomy_term.yml +++ b/core/modules/taxonomy/config/optional/views.view.taxonomy_term.yml @@ -249,7 +249,8 @@ display: - url.query_args - 'user.node_grants:view' - user.permissions - cacheable: false + max-age: -1 + tags: { } feed_1: id: feed_1 display_title: Feed @@ -286,7 +287,8 @@ display: - url - 'user.node_grants:view' - user.permissions - cacheable: false + max-age: -1 + tags: { } page_1: id: page_1 display_title: Page @@ -305,4 +307,5 @@ display: - url.query_args - 'user.node_grants:view' - user.permissions - cacheable: false + max-age: -1 + tags: { } diff --git a/core/modules/taxonomy/src/Plugin/views/argument_default/Tid.php b/core/modules/taxonomy/src/Plugin/views/argument_default/Tid.php index f162195f699e162a0392e54aa29590fe6ed9d377..07dca4cde7b3d32b4b97bf9bf029146157a5acba 100644 --- a/core/modules/taxonomy/src/Plugin/views/argument_default/Tid.php +++ b/core/modules/taxonomy/src/Plugin/views/argument_default/Tid.php @@ -7,10 +7,11 @@ namespace Drupal\taxonomy\Plugin\views\argument_default; +use Drupal\Core\Cache\Cache; +use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\taxonomy\TermInterface; -use Drupal\views\Plugin\CacheablePluginInterface; use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase; @@ -28,7 +29,7 @@ * title = @Translation("Taxonomy term ID from URL") * ) */ -class Tid extends ArgumentDefaultPluginBase implements CacheablePluginInterface { +class Tid extends ArgumentDefaultPluginBase implements CacheableDependencyInterface { /** * The route match. @@ -216,8 +217,8 @@ public function getArgument() { /** * {@inheritdoc} */ - public function isCacheable() { - return TRUE; + public function getCacheMaxAge() { + return Cache::PERMANENT; } /** diff --git a/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.taxonomy_all_terms_test.yml b/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.taxonomy_all_terms_test.yml index ce71f7688b6f1625a5ffea66ca0ac325b31c1865..5e49d66311e4e650d7c8c74b1b59534b4e68bb8e 100644 --- a/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.taxonomy_all_terms_test.yml +++ b/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.taxonomy_all_terms_test.yml @@ -165,7 +165,7 @@ display: - url.query_args - 'user.node_grants:view' - user.permissions - cacheable: false + max-age: 0 page_1: display_plugin: page id: page_1 @@ -255,4 +255,4 @@ display: - url.query_args - 'user.node_grants:view' - user.permissions - cacheable: false + max-age: 0 diff --git a/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_term_relationship.yml b/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_term_relationship.yml index 22521bc1ea68eb58c1705028db34a96388765094..2fb2c30d458ee0e70caad17c3908ac8484ea6533 100644 --- a/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_term_relationship.yml +++ b/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_term_relationship.yml @@ -199,4 +199,4 @@ display: contexts: - 'languages:language_content' - 'languages:language_interface' - cacheable: false + max-age: 0 diff --git a/core/modules/user/config/optional/views.view.user_admin_people.yml b/core/modules/user/config/optional/views.view.user_admin_people.yml index 0ae79660153a0eab4d3a60bc8570f8002cc13d4f..63e127cb74e4fb9fbda6c2914781d9b9b782c074 100644 --- a/core/modules/user/config/optional/views.view.user_admin_people.yml +++ b/core/modules/user/config/optional/views.view.user_admin_people.yml @@ -875,7 +875,8 @@ display: - url - url.query_args - user.permissions - cacheable: false + max-age: 0 + tags: { } page_1: display_plugin: page id: page_1 @@ -907,4 +908,5 @@ display: - url - url.query_args - user.permissions - cacheable: false + max-age: 0 + tags: { } diff --git a/core/modules/user/config/optional/views.view.who_s_new.yml b/core/modules/user/config/optional/views.view.who_s_new.yml index 79fd2a75623294b75348b4ef5be52485d4afcf66..84a3ab0594031bb1dc5f30a8d75a51d0ee0d1ec0 100644 --- a/core/modules/user/config/optional/views.view.who_s_new.yml +++ b/core/modules/user/config/optional/views.view.who_s_new.yml @@ -169,7 +169,8 @@ display: - 'languages:language_content' - 'languages:language_interface' - user.permissions - cacheable: false + max-age: -1 + tags: { } block_1: display_plugin: block id: block_1 @@ -185,4 +186,5 @@ display: - 'languages:language_content' - 'languages:language_interface' - user.permissions - cacheable: false + max-age: -1 + tags: { } diff --git a/core/modules/user/config/optional/views.view.who_s_online.yml b/core/modules/user/config/optional/views.view.who_s_online.yml index 4669e34b1a842c20178d5e721e87097d919553fd..c7604dd07e32cf0208038228443987a99175ecb7 100644 --- a/core/modules/user/config/optional/views.view.who_s_online.yml +++ b/core/modules/user/config/optional/views.view.who_s_online.yml @@ -199,7 +199,8 @@ display: - 'languages:language_content' - 'languages:language_interface' - user.permissions - cacheable: false + max-age: -1 + tags: { } who_s_online_block: display_plugin: block id: who_s_online_block @@ -214,4 +215,5 @@ display: - 'languages:language_content' - 'languages:language_interface' - user.permissions - cacheable: false + max-age: -1 + tags: { } diff --git a/core/modules/user/src/Plugin/views/access/Permission.php b/core/modules/user/src/Plugin/views/access/Permission.php index fab8f882b020422587c5ef7ad844cb295bf1c59d..c54bfff1245816c3c45ea081546a345dd55e5c3e 100644 --- a/core/modules/user/src/Plugin/views/access/Permission.php +++ b/core/modules/user/src/Plugin/views/access/Permission.php @@ -7,11 +7,12 @@ namespace Drupal\user\Plugin\views\access; +use Drupal\Core\Cache\Cache; +use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Session\AccountInterface; use Drupal\user\PermissionHandlerInterface; -use Drupal\views\Plugin\CacheablePluginInterface; use Drupal\views\Plugin\views\access\AccessPluginBase; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Routing\Route; @@ -27,7 +28,7 @@ * help = @Translation("Access will be granted to users with the specified permission string.") * ) */ -class Permission extends AccessPluginBase implements CacheablePluginInterface { +class Permission extends AccessPluginBase implements CacheableDependencyInterface { /** * Overrides Drupal\views\Plugin\Plugin::$usesOptions. @@ -135,8 +136,8 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function isCacheable() { - return TRUE; + public function getCacheMaxAge() { + return Cache::PERMANENT; } /** @@ -146,4 +147,11 @@ public function getCacheContexts() { return ['user.permissions']; } + /** + * {@inheritdoc} + */ + public function getCacheTags() { + return []; + } + } diff --git a/core/modules/user/src/Plugin/views/access/Role.php b/core/modules/user/src/Plugin/views/access/Role.php index 42404cea50433ff77754bb6004e2353607532799..b7bbf509b45c29cf18a488751536b75bc9545fcc 100644 --- a/core/modules/user/src/Plugin/views/access/Role.php +++ b/core/modules/user/src/Plugin/views/access/Role.php @@ -8,9 +8,10 @@ namespace Drupal\user\Plugin\views\access; use Drupal\Component\Utility\SafeMarkup; +use Drupal\Core\Cache\Cache; +use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\user\RoleStorageInterface; -use Drupal\views\Plugin\CacheablePluginInterface; use Drupal\views\Plugin\views\access\AccessPluginBase; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Routing\Route; @@ -27,7 +28,7 @@ * help = @Translation("Access will be granted to users with any of the specified roles.") * ) */ -class Role extends AccessPluginBase implements CacheablePluginInterface { +class Role extends AccessPluginBase implements CacheableDependencyInterface { /** * Overrides Drupal\views\Plugin\Plugin::$usesOptions. @@ -149,8 +150,8 @@ public function calculateDependencies() { /** * {@inheritdoc} */ - public function isCacheable() { - return TRUE; + public function getCacheMaxAge() { + return Cache::PERMANENT; } /** @@ -160,5 +161,12 @@ public function getCacheContexts() { return ['user.roles']; } + /** + * {@inheritdoc} + */ + public function getCacheTags() { + return []; + } + } diff --git a/core/modules/user/src/Plugin/views/argument_default/CurrentUser.php b/core/modules/user/src/Plugin/views/argument_default/CurrentUser.php index b3c86ece49a5b8eb3e5e48e993b7d2497fc256fd..48b2c9c00370ae0ee2569482a67b3602bcc5e59e 100644 --- a/core/modules/user/src/Plugin/views/argument_default/CurrentUser.php +++ b/core/modules/user/src/Plugin/views/argument_default/CurrentUser.php @@ -7,7 +7,8 @@ namespace Drupal\user\Plugin\views\argument_default; -use Drupal\views\Plugin\CacheablePluginInterface; +use Drupal\Core\Cache\Cache; +use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase; /** @@ -20,7 +21,7 @@ * title = @Translation("User ID from logged in user") * ) */ -class CurrentUser extends ArgumentDefaultPluginBase implements CacheablePluginInterface { +class CurrentUser extends ArgumentDefaultPluginBase implements CacheableDependencyInterface { public function getArgument() { return \Drupal::currentUser()->id(); @@ -29,8 +30,8 @@ public function getArgument() { /** * {@inheritdoc} */ - public function isCacheable() { - return TRUE; + public function getCacheMaxAge() { + return Cache::PERMANENT; } /** diff --git a/core/modules/user/src/Plugin/views/argument_default/User.php b/core/modules/user/src/Plugin/views/argument_default/User.php index edfb709921a139f0a8ecb2f0db1afa8f8e75fb5b..faeb4b7b029b53c10d03c6e5d3df4b37903e1871 100644 --- a/core/modules/user/src/Plugin/views/argument_default/User.php +++ b/core/modules/user/src/Plugin/views/argument_default/User.php @@ -7,9 +7,10 @@ namespace Drupal\user\Plugin\views\argument_default; +use Drupal\Core\Cache\Cache; +use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\RouteMatchInterface; -use Drupal\views\Plugin\CacheablePluginInterface; use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; @@ -24,7 +25,7 @@ * title = @Translation("User ID from route context") * ) */ -class User extends ArgumentDefaultPluginBase implements CacheablePluginInterface { +class User extends ArgumentDefaultPluginBase implements CacheableDependencyInterface { /** * The route match. @@ -108,8 +109,8 @@ public function getArgument() { /** * {@inheritdoc} */ - public function isCacheable() { - return TRUE; + public function getCacheMaxAge() { + return Cache::PERMANENT; } /** diff --git a/core/modules/user/src/Tests/Views/AccessRoleTest.php b/core/modules/user/src/Tests/Views/AccessRoleTest.php index efca3e2261ba6a809d570e54807bbeb8aed9f991..6960bc5faaca50e48db7df8bc9aa67ad8afacff1 100644 --- a/core/modules/user/src/Tests/Views/AccessRoleTest.php +++ b/core/modules/user/src/Tests/Views/AccessRoleTest.php @@ -7,6 +7,7 @@ namespace Drupal\user\Tests\Views; +use Drupal\Core\Cache\Cache; use Drupal\user\Plugin\views\access\Role; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Views; @@ -58,10 +59,12 @@ function testAccessRole() { $this->drupalLogin($this->webUser); $this->drupalGet('test-role'); $this->assertResponse(403); + $this->assertCacheContext('user.roles'); $this->drupalLogin($this->normalUser); $this->drupalGet('test-role'); $this->assertResponse(200); + $this->assertCacheContext('user.roles'); // Test allowing multiple roles. $view = Views::getView('test_access_role')->storage; @@ -85,12 +88,15 @@ function testAccessRole() { $this->drupalLogin($this->webUser); $this->drupalGet('test-role'); $this->assertResponse(403); + $this->assertCacheContext('user.roles'); $this->drupalLogout(); $this->drupalGet('test-role'); $this->assertResponse(200); + $this->assertCacheContext('user.roles'); $this->drupalLogin($this->normalUser); $this->drupalGet('test-role'); $this->assertResponse(200); + $this->assertCacheContext('user.roles'); } /** @@ -112,17 +118,25 @@ public function testRenderCaching() { /** @var \Drupal\Core\Session\AccountSwitcherInterface $account_switcher */ $account_switcher = \Drupal::service('account_switcher'); - - // First access as user without access. + // First access as user with access. $build = DisplayPluginBase::buildBasicRenderable('test_access_role', 'default'); $account_switcher->switchTo($this->normalUser); $result = $renderer->renderPlain($build); + $this->assertTrue(in_array('user.roles', $build['#cache']['contexts'])); + $this->assertEqual(['config:views.view.test_access_role'], $build['#cache']['tags']); + $this->assertEqual(Cache::PERMANENT, $build['#cache']['max-age']); $this->assertNotEqual($result, ''); - // Then with access. + // Then without access. $build = DisplayPluginBase::buildBasicRenderable('test_access_role', 'default'); $account_switcher->switchTo($this->webUser); $result = $renderer->renderPlain($build); + // @todo Fix this in https://www.drupal.org/node/2551037, + // DisplayPluginBase::applyDisplayCachablityMetadata() is not invoked when + // using buildBasicRenderable() and a Views access plugin returns FALSE. + //$this->assertTrue(in_array('user.roles', $build['#cache']['contexts'])); + //$this->assertEqual([], $build['#cache']['tags']); + $this->assertEqual(Cache::PERMANENT, $build['#cache']['max-age']); $this->assertEqual($result, ''); } diff --git a/core/modules/views/config/schema/views.schema.yml b/core/modules/views/config/schema/views.schema.yml index 7ea599d32ec4b8e68f8284399cb8218d26fbf6fa..6a6c321956a8c427521abfff39a7567e777f0bb5 100644 --- a/core/modules/views/config/schema/views.schema.yml +++ b/core/modules/views/config/schema/views.schema.yml @@ -118,15 +118,23 @@ views.view.*: type: mapping label: 'Cache metadata' mapping: - cacheable: - type: boolean - label: 'Cacheable' + max-age: + type: integer + label: 'Cache maximum age' contexts: type: sequence label: 'Cache contexts' sequence: type: string - + tags: + type: sequence + label: 'Cache tags' + sequence: + type: string + # Deprecated. + cacheable: + type: boolean + label: 'Cacheable' views_block: type: block_settings label: 'View block' diff --git a/core/modules/views/src/Entity/Render/RendererBase.php b/core/modules/views/src/Entity/Render/RendererBase.php index deb1806e3ac838e97668db6b9fc88d91385cc2ac..19f98c37e3a9bdd9d6a8785345ff0ee05f6196ad 100644 --- a/core/modules/views/src/Entity/Render/RendererBase.php +++ b/core/modules/views/src/Entity/Render/RendererBase.php @@ -7,9 +7,10 @@ namespace Drupal\views\Entity\Render; +use Drupal\Core\Cache\Cache; +use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Language\LanguageManagerInterface; -use Drupal\views\Plugin\CacheablePluginInterface; use Drupal\views\Plugin\views\query\QueryPluginBase; use Drupal\views\ResultRow; use Drupal\views\ViewExecutable; @@ -17,7 +18,7 @@ /** * Defines a base class for entity renderers. */ -abstract class RendererBase implements CacheablePluginInterface { +abstract class RendererBase implements CacheableDependencyInterface { /** * The view executable wrapping the view storage entity. @@ -66,8 +67,8 @@ public function __construct(ViewExecutable $view, LanguageManagerInterface $lang /** * {@inheritdoc} */ - public function isCacheable() { - return TRUE; + public function getCacheMaxAge() { + return Cache::PERMANENT; } /** @@ -77,6 +78,13 @@ public function getCacheContexts() { return []; } + /** + * {@inheritdoc} + */ + public function getCacheTags() { + return []; + } + /** * Alters the query if needed. * diff --git a/core/modules/views/src/Entity/View.php b/core/modules/views/src/Entity/View.php index d5344f486dc24da7585ed79eba079ca308588b90..775efdb8cf4717b9daf4fc454e1a3a7647aacd64 100644 --- a/core/modules/views/src/Entity/View.php +++ b/core/modules/views/src/Entity/View.php @@ -311,8 +311,9 @@ public function preSave(EntityStorageInterface $storage) { * * Cache metadata is set per view and per display, and ends up being stored in * the view's configuration. This allows Views to determine very efficiently: - * - whether a view is cacheable at all - * - what the cache key for a given view should be + * - the max-age + * - the cache contexts + * - the cache tags * * In other words: this allows us to do the (expensive) work of initializing * Views plugins and handlers to determine their effect on the cacheability of @@ -327,7 +328,10 @@ protected function addCacheMetadata() { $display =& $this->getDisplay($display_id); $executable->setDisplay($display_id); - list($display['cache_metadata']['cacheable'], $display['cache_metadata']['contexts']) = $executable->getDisplay()->calculateCacheMetadata(); + $cache_metadata = $executable->getDisplay()->calculateCacheMetadata(); + $display['cache_metadata']['max-age'] = $cache_metadata->getCacheMaxAge(); + $display['cache_metadata']['contexts'] = $cache_metadata->getCacheContexts(); + $display['cache_metadata']['tags'] = $cache_metadata->getCacheTags(); // Always include at least the 'languages:' context as there will most // probably be translatable strings in the view output. $display['cache_metadata']['contexts'] = Cache::mergeContexts($display['cache_metadata']['contexts'], ['languages:' . LanguageInterface::TYPE_INTERFACE]); diff --git a/core/modules/views/src/EventSubscriber/ViewsEntitySchemaSubscriber.php b/core/modules/views/src/EventSubscriber/ViewsEntitySchemaSubscriber.php index 1904838cecdeed2028b9306ff16e9271c93a8a77..aa956ccc92ae97ac115e41c61730ee21fbe8c8b2 100644 --- a/core/modules/views/src/EventSubscriber/ViewsEntitySchemaSubscriber.php +++ b/core/modules/views/src/EventSubscriber/ViewsEntitySchemaSubscriber.php @@ -188,7 +188,11 @@ public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeI } foreach ($all_views as $view) { - $view->save(); + // All changes done to the views here can be trusted and this might be + // called during updates, when it is not safe to rely on configuration + // containing valid schema. Trust the data and disable schema validation + // and casting. + $view->trustData()->save(); } } diff --git a/core/modules/views/src/Plugin/CacheablePluginInterface.php b/core/modules/views/src/Plugin/CacheablePluginInterface.php deleted file mode 100644 index b700ce7c2de792c6fcf9e570189bdf2bb450100e..0000000000000000000000000000000000000000 --- a/core/modules/views/src/Plugin/CacheablePluginInterface.php +++ /dev/null @@ -1,35 +0,0 @@ -getPlugin('argument_default')) && $plugin instanceof CacheablePluginInterface) { - $result &= $plugin->isCacheable(); + if (($plugin = $this->getPlugin('argument_default')) && $plugin instanceof CacheableDependencyInterface) { + $max_age = Cache::mergeMaxAges($max_age, $plugin->getCacheMaxAge()); } - if (($plugin = $this->getPlugin('argument_validator')) && $plugin instanceof CacheablePluginInterface) { - $result &= $plugin->isCacheable(); + if (($plugin = $this->getPlugin('argument_validator')) && $plugin instanceof CacheableDependencyInterface) { + $max_age = Cache::mergeMaxAges($max_age, $plugin->getCacheMaxAge()); } // Summaries use style plugins. - if (($plugin = $this->getPlugin('style')) && $plugin instanceof CacheablePluginInterface) { - $result &= $plugin->isCacheable(); + if (($plugin = $this->getPlugin('style')) && $plugin instanceof CacheableDependencyInterface) { + $max_age = Cache::mergeMaxAges($max_age, $plugin->getCacheMaxAge()); } - return $result; + return $max_age; } /** @@ -1266,21 +1267,43 @@ public function getCacheContexts() { $contexts[] = 'url'; // Asks all subplugins (argument defaults, argument validator and styles). - if (($plugin = $this->getPlugin('argument_default')) && $plugin instanceof CacheablePluginInterface) { - $contexts = array_merge($plugin->getCacheContexts(), $contexts); + if (($plugin = $this->getPlugin('argument_default')) && $plugin instanceof CacheableDependencyInterface) { + $contexts = Cache::mergeContexts($contexts, $plugin->getCacheContexts()); } - if (($plugin = $this->getPlugin('argument_validator')) && $plugin instanceof CacheablePluginInterface) { - $contexts = array_merge($plugin->getCacheContexts(), $contexts); + if (($plugin = $this->getPlugin('argument_validator')) && $plugin instanceof CacheableDependencyInterface) { + $contexts = Cache::mergeContexts($contexts, $plugin->getCacheContexts()); } - if (($plugin = $this->getPlugin('style')) && $plugin instanceof CacheablePluginInterface) { - $contexts = array_merge($plugin->getCacheContexts(), $contexts); + if (($plugin = $this->getPlugin('style')) && $plugin instanceof CacheableDependencyInterface) { + $contexts = Cache::mergeContexts($contexts, $plugin->getCacheContexts()); } return $contexts; } + /** + * {@inheritdoc} + */ + public function getCacheTags() { + $tags = []; + + // Asks all subplugins (argument defaults, argument validator and styles). + if (($plugin = $this->getPlugin('argument_default')) && $plugin instanceof CacheableDependencyInterface) { + $tags = Cache::mergeTags($tags, $plugin->getCacheTags()); + } + + if (($plugin = $this->getPlugin('argument_validator')) && $plugin instanceof CacheableDependencyInterface) { + $tags = Cache::mergeTags($tags, $plugin->getCacheTags()); + } + + if (($plugin = $this->getPlugin('style')) && $plugin instanceof CacheableDependencyInterface) { + $tags = Cache::mergeTags($tags, $plugin->getCacheTags()); + } + + return $tags; + } + /** * {@inheritdoc} */ diff --git a/core/modules/views/src/Plugin/views/argument_default/ArgumentDefaultPluginBase.php b/core/modules/views/src/Plugin/views/argument_default/ArgumentDefaultPluginBase.php index b5c2adf756de433060daceaf4150c27fdae224ae..b9ebbbc2ea8c274fee23cca54700b1ccc63602e3 100644 --- a/core/modules/views/src/Plugin/views/argument_default/ArgumentDefaultPluginBase.php +++ b/core/modules/views/src/Plugin/views/argument_default/ArgumentDefaultPluginBase.php @@ -102,6 +102,13 @@ protected function checkAccess(&$form, $option_name) { } } + /** + * {@inheritdoc} + */ + public function getCacheTags() { + return []; + } + } /** diff --git a/core/modules/views/src/Plugin/views/argument_default/Fixed.php b/core/modules/views/src/Plugin/views/argument_default/Fixed.php index 99f55ae6405a627d0b401c44961cc82c29b1705e..096794e2f1025dea8acca501b1b008ef4b9f56d8 100644 --- a/core/modules/views/src/Plugin/views/argument_default/Fixed.php +++ b/core/modules/views/src/Plugin/views/argument_default/Fixed.php @@ -7,8 +7,9 @@ namespace Drupal\views\Plugin\views\argument_default; +use Drupal\Core\Cache\Cache; +use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\views\Plugin\CacheablePluginInterface; /** * The fixed argument default handler. @@ -20,7 +21,7 @@ * title = @Translation("Fixed") * ) */ -class Fixed extends ArgumentDefaultPluginBase implements CacheablePluginInterface { +class Fixed extends ArgumentDefaultPluginBase implements CacheableDependencyInterface { protected function defineOptions() { $options = parent::defineOptions(); @@ -48,8 +49,8 @@ public function getArgument() { /** * {@inheritdoc} */ - public function isCacheable() { - return TRUE; + public function getCacheMaxAge() { + return Cache::PERMANENT; } /** diff --git a/core/modules/views/src/Plugin/views/argument_default/QueryParameter.php b/core/modules/views/src/Plugin/views/argument_default/QueryParameter.php index feccd21e1d29068388d4a9103bdfcc64dafe8dab..57f8f895d979efb06b59f4b90b451003fee4ac42 100644 --- a/core/modules/views/src/Plugin/views/argument_default/QueryParameter.php +++ b/core/modules/views/src/Plugin/views/argument_default/QueryParameter.php @@ -7,8 +7,9 @@ namespace Drupal\views\Plugin\views\argument_default; +use Drupal\Core\Cache\Cache; +use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\views\Plugin\CacheablePluginInterface; /** * A query parameter argument default handler. @@ -20,7 +21,7 @@ * title = @Translation("Query parameter") * ) */ -class QueryParameter extends ArgumentDefaultPluginBase implements CacheablePluginInterface { +class QueryParameter extends ArgumentDefaultPluginBase implements CacheableDependencyInterface { /** * {@inheritdoc} @@ -87,8 +88,8 @@ public function getArgument() { /** * {@inheritdoc} */ - public function isCacheable() { - return TRUE; + public function getCacheMaxAge() { + return Cache::PERMANENT; } /** diff --git a/core/modules/views/src/Plugin/views/argument_default/Raw.php b/core/modules/views/src/Plugin/views/argument_default/Raw.php index 20715f341ef19b6e7d5f36bb3ee7c62343e0a4f8..77299fd39f86e9cded58ce2af1113da0e8a18e64 100644 --- a/core/modules/views/src/Plugin/views/argument_default/Raw.php +++ b/core/modules/views/src/Plugin/views/argument_default/Raw.php @@ -7,10 +7,11 @@ namespace Drupal\views\Plugin\views\argument_default; +use Drupal\Core\Cache\Cache; +use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Path\AliasManagerInterface; use Drupal\Core\Path\CurrentPathStack; -use Drupal\views\Plugin\CacheablePluginInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; @@ -24,7 +25,7 @@ * title = @Translation("Raw value from URL") * ) */ -class Raw extends ArgumentDefaultPluginBase implements CacheablePluginInterface { +class Raw extends ArgumentDefaultPluginBase implements CacheableDependencyInterface { /** * The alias manager. @@ -116,8 +117,8 @@ public function getArgument() { /** * {@inheritdoc} */ - public function isCacheable() { - return TRUE; + public function getCacheMaxAge() { + return Cache::PERMANENT; } /** diff --git a/core/modules/views/src/Plugin/views/cache/CachePluginBase.php b/core/modules/views/src/Plugin/views/cache/CachePluginBase.php index 3a38dd0c46a1078601d00f78d33c8cfc3174b49a..9b311263916f6bcab7087bf12c3ad15cb0463415 100644 --- a/core/modules/views/src/Plugin/views/cache/CachePluginBase.php +++ b/core/modules/views/src/Plugin/views/cache/CachePluginBase.php @@ -8,6 +8,7 @@ namespace Drupal\views\Plugin\views\cache; use Drupal\Core\Cache\Cache; +use Drupal\Core\Cache\CacheableMetadata; use Drupal\views\Plugin\views\PluginBase; use Drupal\Core\Database\Query\Select; use Drupal\views\ResultRow; @@ -211,7 +212,7 @@ public function generateResultsKey() { 'items_per_page' => $this->view->getItemsPerPage(), 'offset' => $this->view->getOffset(), ]; - $key_data += \Drupal::service('cache_contexts_manager')->convertTokensToKeys($this->displayHandler->getCacheMetadata()['contexts'])->getKeys(); + $key_data += \Drupal::service('cache_contexts_manager')->convertTokensToKeys($this->displayHandler->getCacheMetadata()->getCacheContexts())->getKeys(); $this->resultsKey = $this->view->storage->id() . ':' . $this->displayHandler->display['id'] . ':results:' . hash('sha256', serialize($key_data)); } @@ -288,12 +289,10 @@ protected function prepareViewResult(array $result) { /** * Alters the cache metadata of a display upon saving a view. * - * @param bool $is_cacheable - * Whether the display is cacheable. - * @param string[] $cache_contexts - * The cache contexts the display varies by. + * @param \Drupal\Core\Cache\CacheableMetadata $cache_metadata + * The cache metadata. */ - public function alterCacheMetadata(&$is_cacheable, array &$cache_contexts) { + public function alterCacheMetadata(CacheableMetadata $cache_metadata) { } /** diff --git a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php index a0ab0cb7740c1e7f1ba90ab26881919e47a0d6c3..a9eabfc37ade16401e768df07f0d527fe0479243 100644 --- a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php @@ -12,6 +12,7 @@ use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Plugin\PluginDependencyTrait; @@ -19,7 +20,6 @@ use Drupal\Core\Theme\Registry; use Drupal\Core\Url; use Drupal\views\Form\ViewsForm; -use Drupal\views\Plugin\CacheablePluginInterface; use Drupal\views\Plugin\views\area\AreaPluginBase; use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\PluginBase; @@ -2149,9 +2149,9 @@ protected function applyDisplayCachablityMetadata(array &$element) { $cache = $this->getPlugin('cache'); (new CacheableMetadata()) - ->setCacheTags($this->view->getCacheTags()) + ->setCacheTags(Cache::mergeTags($this->view->getCacheTags(), isset($this->display['cache_metadata']['tags']) ? $this->display['cache_metadata']['tags'] : [])) ->setCacheContexts(isset($this->display['cache_metadata']['contexts']) ? $this->display['cache_metadata']['contexts'] : []) - ->setCacheMaxAge($cache->getCacheMaxAge()) + ->setCacheMaxAge(Cache::mergeMaxAges($cache->getCacheMaxAge(), isset($this->display['cache_metadata']['max-age']) ? $this->display['cache_metadata']['max-age'] : Cache::PERMANENT)) ->merge(CacheableMetadata::createFromRenderArray($element)) ->applyTo($element); } @@ -2271,18 +2271,13 @@ public function preExecute() { * {@inheritdoc} */ public function calculateCacheMetadata () { - $is_cacheable = TRUE; - $cache_contexts = []; + $cache_metadata = new CacheableMetadata(); // Iterate over ordinary views plugins. foreach (Views::getPluginTypes('plugin') as $plugin_type) { $plugin = $this->getPlugin($plugin_type); - if ($plugin instanceof CacheablePluginInterface) { - $cache_contexts = array_merge($cache_contexts, $plugin->getCacheContexts()); - $is_cacheable &= $plugin->isCacheable(); - } - else { - $is_cacheable = FALSE; + if ($plugin instanceof CacheableDependencyInterface) { + $cache_metadata = $cache_metadata->merge(CacheableMetadata::createFromObject($plugin)); } } @@ -2291,19 +2286,18 @@ public function calculateCacheMetadata () { foreach (array_keys(Views::getHandlerTypes()) as $handler_type) { $handlers = $this->getHandlers($handler_type); foreach ($handlers as $handler) { - if ($handler instanceof CacheablePluginInterface) { - $cache_contexts = array_merge($cache_contexts, $handler->getCacheContexts()); - $is_cacheable &= $handler->isCacheable(); + if ($handler instanceof CacheableDependencyInterface) { + $cache_metadata = $cache_metadata->merge(CacheableMetadata::createFromObject($handler)); } } } /** @var \Drupal\views\Plugin\views\cache\CachePluginBase $cache_plugin */ if ($cache_plugin = $this->getPlugin('cache')) { - $cache_plugin->alterCacheMetadata($is_cacheable, $cache_contexts); + $cache_plugin->alterCacheMetadata($cache_metadata); } - return [(bool) $is_cacheable, $cache_contexts]; + return $cache_metadata; } /** @@ -2311,9 +2305,18 @@ public function calculateCacheMetadata () { */ public function getCacheMetadata() { if (!isset($this->display['cache_metadata'])) { - list($this->display['cache_metadata']['cacheable'], $this->display['cache_metadata']['contexts']) = $this->calculateCacheMetadata(); + $cache_metadata = $this->calculateCacheMetadata(); + $this->display['cache_metadata']['max-age'] = $cache_metadata->getCacheMaxAge(); + $this->display['cache_metadata']['contexts'] = $cache_metadata->getCacheContexts(); + $this->display['cache_metadata']['tags'] = $cache_metadata->getCacheTags(); + } + else { + $cache_metadata = (new CacheableMetadata()) + ->setCacheMaxAge($this->display['cache_metadata']['max-age']) + ->setCacheContexts($this->display['cache_metadata']['contexts']) + ->setCacheTags($this->display['cache_metadata']['tags']); } - return $this->display['cache_metadata']; + return $cache_metadata; } /** diff --git a/core/modules/views/src/Plugin/views/display/DisplayPluginInterface.php b/core/modules/views/src/Plugin/views/display/DisplayPluginInterface.php index 780073be3e2a0315914175801fb7a1e0804007c4..666ed52625fc7d9af162e99fd712866db47b4873 100644 --- a/core/modules/views/src/Plugin/views/display/DisplayPluginInterface.php +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginInterface.php @@ -429,20 +429,16 @@ public function preExecute(); /** * Calculates the display's cache metadata by inspecting each handler/plugin. * - * @return array - * Returns an array: - * - first value: (boolean) Whether the display is cacheable. - * - second value: (string[]) The cache contexts the display varies by. + * @return \Drupal\Core\Cache\CacheableMetadata + * The cache metadata. */ public function calculateCacheMetadata(); /** * Gets the cache metadata. * - * @return array - * Returns an array: - * - first value: (boolean) Whether the display is cacheable. - * - second value: (string[]) The cache contexts the display varies by. + * @return \Drupal\Core\Cache\CacheableMetadata + * The cache metadata. */ public function getCacheMetadata(); diff --git a/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php b/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php index 60d0b66ba879bad80834d92fb5c63d4896348118..c30f899229fd5a91a3cc42a241437be4140ef601 100644 --- a/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php +++ b/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php @@ -8,10 +8,11 @@ namespace Drupal\views\Plugin\views\exposed_form; use Drupal\Component\Utility\Html; +use Drupal\Core\Cache\Cache; +use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Form\FormState; use Drupal\Core\Form\FormStateInterface; use Drupal\views\Form\ViewsExposedForm; -use Drupal\views\Plugin\CacheablePluginInterface; use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\PluginBase; @@ -35,7 +36,7 @@ /** * Base class for Views exposed filter form plugins. */ -abstract class ExposedFormPluginBase extends PluginBase implements CacheablePluginInterface { +abstract class ExposedFormPluginBase extends PluginBase implements CacheableDependencyInterface { /** * Overrides Drupal\views\Plugin\Plugin::$usesOptions. @@ -336,8 +337,8 @@ public function resetForm(&$form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function isCacheable() { - return TRUE; + public function getCacheMaxAge() { + return Cache::PERMANENT; } /** @@ -364,6 +365,13 @@ public function getCacheContexts() { return $contexts; } + /** + * {@inheritdoc} + */ + public function getCacheTags() { + return []; + } + } /** diff --git a/core/modules/views/src/Plugin/views/field/Field.php b/core/modules/views/src/Plugin/views/field/Field.php index e4e3b0af747de44836d6ab11972eecb9803baa23..33253d11c99916f577c4d97165874e46dff08a4d 100644 --- a/core/modules/views/src/Plugin/views/field/Field.php +++ b/core/modules/views/src/Plugin/views/field/Field.php @@ -8,6 +8,8 @@ namespace Drupal\views\Plugin\views\field; use Drupal\Component\Utility\Xss; +use Drupal\Core\Cache\Cache; +use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface; @@ -22,7 +24,6 @@ use Drupal\Core\Session\AccountInterface; use Drupal\views\FieldAPIHandlerTrait; use Drupal\views\Entity\Render\EntityFieldRenderer; -use Drupal\views\Plugin\CacheablePluginInterface; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\ResultRow; use Drupal\views\ViewExecutable; @@ -37,7 +38,7 @@ * * @ViewsField("field") */ -class Field extends FieldPluginBase implements CacheablePluginInterface, MultiItemsFieldHandlerInterface { +class Field extends FieldPluginBase implements CacheableDependencyInterface, MultiItemsFieldHandlerInterface { use FieldAPIHandlerTrait; /** @@ -961,8 +962,8 @@ public function calculateDependencies() { /** * {@inheritdoc} */ - public function isCacheable() { - return FALSE; + public function getCacheMaxAge() { + return Cache::PERMANENT; } /** @@ -972,6 +973,18 @@ public function getCacheContexts() { return $this->getEntityFieldRenderer()->getCacheContexts(); } + /** + * {@inheritdoc} + */ + public function getCacheTags() { + $field_definition = $this->getFieldDefinition(); + $field_storage_definition = $this->getFieldStorageDefinition(); + return Cache::mergeTags( + $field_definition instanceof CacheableDependencyInterface ? $field_definition->getCacheTags() : [], + $field_storage_definition instanceof CacheableDependencyInterface ? $field_storage_definition->getCacheTags() : [] + ); + } + /** * Gets the table mapping for the entity type of the field. * diff --git a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php index 1e401ff0d3cbcfcdfd6a5cffc3c2cc33be5c0cc4..dade1dfa7d433f4ea4c6c3825622ed5fd828fd79 100644 --- a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php +++ b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php @@ -7,11 +7,12 @@ namespace Drupal\views\Plugin\views\filter; +use Drupal\Core\Cache\Cache; +use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Form\FormHelper; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; use Drupal\user\RoleInterface; -use Drupal\views\Plugin\CacheablePluginInterface; use Drupal\views\Plugin\views\HandlerBase; use Drupal\Component\Utility\Html; use Drupal\views\Plugin\views\display\DisplayPluginBase; @@ -46,7 +47,7 @@ /** * Base class for Views filters handler plugins. */ -abstract class FilterPluginBase extends HandlerBase implements CacheablePluginInterface { +abstract class FilterPluginBase extends HandlerBase implements CacheableDependencyInterface { /** * Contains the actual value of the field,either configured in the views ui @@ -1464,8 +1465,8 @@ protected static function arrayFilterZero($var) { /** * {@inheritdoc} */ - public function isCacheable() { - return TRUE; + public function getCacheMaxAge() { + return Cache::PERMANENT; } /** @@ -1482,6 +1483,13 @@ public function getCacheContexts() { return $cache_contexts; } + /** + * {@inheritdoc} + */ + public function getCacheTags() { + return []; + } + } /** diff --git a/core/modules/views/src/Plugin/views/pager/SqlBase.php b/core/modules/views/src/Plugin/views/pager/SqlBase.php index 4262701d9f16cfc85f5d7b8710f526458102ca60..fb590e6c631e64261ec5dae794f7d0bb3aa27ac1 100644 --- a/core/modules/views/src/Plugin/views/pager/SqlBase.php +++ b/core/modules/views/src/Plugin/views/pager/SqlBase.php @@ -7,13 +7,14 @@ namespace Drupal\views\Plugin\views\pager; +use Drupal\Core\Cache\Cache; +use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\views\Plugin\CacheablePluginInterface; /** * A common base class for sql based pager. */ -abstract class SqlBase extends PagerPluginBase implements CacheablePluginInterface { +abstract class SqlBase extends PagerPluginBase implements CacheableDependencyInterface { protected function defineOptions() { $options = parent::defineOptions(); @@ -374,8 +375,8 @@ public function exposedFormValidate(&$form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function isCacheable() { - return TRUE; + public function getCacheMaxAge() { + return Cache::PERMANENT; } /** @@ -387,4 +388,11 @@ public function getCacheContexts() { return ['url.query_args']; } + /** + * {@inheritdoc} + */ + public function getCacheTags() { + return []; + } + } diff --git a/core/modules/views/src/Plugin/views/query/QueryPluginBase.php b/core/modules/views/src/Plugin/views/query/QueryPluginBase.php index 97498e95ca1baa51b14c12114ce6606344861205..f73f16f70514502cf65610f14c9834b8c2332204 100644 --- a/core/modules/views/src/Plugin/views/query/QueryPluginBase.php +++ b/core/modules/views/src/Plugin/views/query/QueryPluginBase.php @@ -8,8 +8,8 @@ namespace Drupal\views\Plugin\views\query; use Drupal\Core\Cache\Cache; +use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\views\Plugin\CacheablePluginInterface; use Drupal\views\Plugin\views\PluginBase; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\ViewExecutable; @@ -37,7 +37,7 @@ /** * Base plugin class for Views queries. */ -abstract class QueryPluginBase extends PluginBase implements CacheablePluginInterface { +abstract class QueryPluginBase extends PluginBase implements CacheableDependencyInterface { /** * A pager plugin that should be provided by the display. @@ -320,9 +320,8 @@ public function getEntityTableInfo() { /** * {@inheritdoc} */ - public function isCacheable() { - // This plugin can't really determine that. - return TRUE; + public function getCacheMaxAge() { + return Cache::PERMANENT; } /** @@ -345,13 +344,6 @@ public function getCacheTags() { return []; } - /** - * {@inheritdoc} - */ - public function getCacheMaxAge() { - return Cache::PERMANENT; - } - } /** diff --git a/core/modules/views/src/Plugin/views/sort/Random.php b/core/modules/views/src/Plugin/views/sort/Random.php index 9d8fdbbdb76c8791e915da989ed09e2b3b0b8681..944ac7f6ee7762dcd8a78b06d5b9e16d0bfa62f6 100644 --- a/core/modules/views/src/Plugin/views/sort/Random.php +++ b/core/modules/views/src/Plugin/views/sort/Random.php @@ -7,15 +7,15 @@ namespace Drupal\views\Plugin\views\sort; +use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\views\Plugin\CacheablePluginInterface; /** * Handle a random sort. * * @ViewsSort("random") */ -class Random extends SortPluginBase implements CacheablePluginInterface { +class Random extends SortPluginBase implements CacheableDependencyInterface { /** * {@inheritdoc} @@ -26,8 +26,6 @@ public function usesGroupBy() { public function query() { $this->query->addOrderBy('rand'); - // @todo Replace this once https://www.drupal.org/node/2464427 is in. - $this->view->element['#cache']['max-age'] = 0; } public function buildOptionsForm(&$form, FormStateInterface $form_state) { @@ -38,8 +36,8 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function isCacheable() { - return FALSE; + public function getCacheMaxAge() { + return 0; } /** @@ -49,4 +47,11 @@ public function getCacheContexts() { return []; } + /** + * {@inheritdoc} + */ + public function getCacheTags() { + return []; + } + } diff --git a/core/modules/views/src/Plugin/views/sort/SortPluginBase.php b/core/modules/views/src/Plugin/views/sort/SortPluginBase.php index 81b4505e40cc9e19dee6fc3ff581ae90a45f1dc4..ca595fbe2c548a510575adc3faf5addd6df155f5 100644 --- a/core/modules/views/src/Plugin/views/sort/SortPluginBase.php +++ b/core/modules/views/src/Plugin/views/sort/SortPluginBase.php @@ -7,8 +7,9 @@ namespace Drupal\views\Plugin\views\sort; +use Drupal\Core\Cache\Cache; +use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\views\Plugin\CacheablePluginInterface; use Drupal\views\Plugin\views\HandlerBase; /** @@ -27,7 +28,7 @@ /** * Base sort handler that has no options and performs a simple sort. */ -abstract class SortPluginBase extends HandlerBase implements CacheablePluginInterface { +abstract class SortPluginBase extends HandlerBase implements CacheableDependencyInterface { /** * Determine if a sort can be exposed. @@ -227,10 +228,10 @@ public function defaultExposeOptions() { /** * {@inheritdoc} */ - public function isCacheable() { + public function getCacheMaxAge() { // The result of a sort does not depend on outside information, so by // default it is cacheable. - return TRUE; + return Cache::PERMANENT; } /** @@ -245,6 +246,13 @@ public function getCacheContexts() { return $cache_contexts; } + /** + * {@inheritdoc} + */ + public function getCacheTags() { + return []; + } + } /** diff --git a/core/modules/views/src/Plugin/views/style/Table.php b/core/modules/views/src/Plugin/views/style/Table.php index 6e4e15827b255bf70ef27994e419b7f4401b45c8..92cd120a224add8422f54079f62e64fc3af4d904 100644 --- a/core/modules/views/src/Plugin/views/style/Table.php +++ b/core/modules/views/src/Plugin/views/style/Table.php @@ -9,8 +9,8 @@ use Drupal\Component\Plugin\Discovery\DiscoveryInterface; use Drupal\Component\Utility\Html; +use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\views\Plugin\CacheablePluginInterface; use Drupal\views\Plugin\views\wizard\WizardInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; @@ -28,7 +28,7 @@ * display_types = {"normal"} * ) */ -class Table extends StylePluginBase implements CacheablePluginInterface { +class Table extends StylePluginBase implements CacheableDependencyInterface { /** * Does the style plugin for itself support to add fields to it's output. @@ -432,8 +432,8 @@ public function wizardSubmit(&$form, FormStateInterface $form_state, WizardInter /** * {@inheritdoc} */ - public function isCacheable() { - return TRUE; + public function getCacheMaxAge() { + return 0; } /** @@ -454,4 +454,11 @@ public function getCacheContexts() { return $contexts; } + /** + * {@inheritdoc} + */ + public function getCacheTags() { + return []; + } + } diff --git a/core/modules/views/src/Tests/GlossaryTest.php b/core/modules/views/src/Tests/GlossaryTest.php index d5a6aaef9105af24a740220005427a6eeaf192d1..d79b183d598019b8624aae883698d51d41c3dd0f 100644 --- a/core/modules/views/src/Tests/GlossaryTest.php +++ b/core/modules/views/src/Tests/GlossaryTest.php @@ -85,7 +85,18 @@ public function testGlossaryView() { ], [ 'config:views.view.glossary', + // Listed for letter 'a' 'node:' . $nodes_by_char['a'][0]->id(), 'node:' . $nodes_by_char['a'][1]->id(), 'node:' . $nodes_by_char['a'][2]->id(), + // Link for letter 'd'. + 'node:1', + // Link for letter 'p'. + 'node:16', + // Link for letter 'r'. + 'node:2', + // Link for letter 'l'. + 'node:21', + // Link for letter 'u'. + 'node:6', 'node_list', 'user:0', 'user_list', diff --git a/core/modules/views/src/Tests/Update/CacheabilityMetadataUpdateTest.php b/core/modules/views/src/Tests/Update/CacheabilityMetadataUpdateTest.php new file mode 100644 index 0000000000000000000000000000000000000000..5de6a0fa1bb27dd90a7c453116e0fc63d919dcdc --- /dev/null +++ b/core/modules/views/src/Tests/Update/CacheabilityMetadataUpdateTest.php @@ -0,0 +1,46 @@ +databaseDumpFiles = [__DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz']; + } + + /** + * Tests that views cacheability metadata updated properly. + */ + public function testUpdateHookN() { + $this->runUpdates(); + foreach (Views::getAllViews() as $view) { + $displays = $view->get('display'); + foreach (array_keys($displays) as $display_id) { + $display = $view->getDisplay($display_id); + $this->assertFalse(isset($display['cache_metadata']['cacheable'])); + $this->assertTrue(isset($display['cache_metadata']['contexts'])); + $this->assertTrue(isset($display['cache_metadata']['max-age'])); + $this->assertTrue(isset($display['cache_metadata']['tags'])); + } + } + } + +} diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.numeric_test.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.numeric_test.yml index 8593665cac5e72c0fa8de05dde3659b51ae9d5e5..29fcef66d71af7736129a232a91c0690102a21e4 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.numeric_test.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.numeric_test.yml @@ -174,7 +174,7 @@ display: cache_metadata: contexts: - language - cacheable: false + max-age: 0 page_1: display_plugin: page id: page_1 @@ -186,4 +186,4 @@ display: cache_metadata: contexts: - language - cacheable: false + max-age: 0 diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_entity_test_link.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_entity_test_link.yml index 509826c6b7fecf274877e8ba2a266d973d56642c..bb19ef0f57d5f47eb3ea1391ca261731054e5294 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_entity_test_link.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_entity_test_link.yml @@ -323,4 +323,4 @@ display: - entity_test_view_grants - 'languages:language_content' - 'languages:language_interface' - cacheable: false + max-age: 0 diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_feed_icon.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_feed_icon.yml index a5bb9f52e694182323357d5fca156eb1d562b8de..acb6acb0a26f8c6a82d38ab50ddc4b35fa9afd41 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_feed_icon.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_feed_icon.yml @@ -174,7 +174,7 @@ display: - 'languages:language_interface' - url - 'user.node_grants:view' - cacheable: false + max-age: 0 feed_1: display_plugin: feed id: feed_1 @@ -198,7 +198,7 @@ display: - 'languages:language_interface' - url - 'user.node_grants:view' - cacheable: false + max-age: 0 page_1: display_plugin: page id: page_1 @@ -213,4 +213,4 @@ display: - 'languages:language_interface' - url - 'user.node_grants:view' - cacheable: false + max-age: 0 diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_field_field_attachment_test.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_field_field_attachment_test.yml index eae936f7f59867286555677d1bdc378c3667141e..e09726426b4016dd01bc225d8e2f503eb36c1133 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_field_field_attachment_test.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_field_field_attachment_test.yml @@ -137,4 +137,4 @@ display: contexts: - 'languages:language_content' - 'languages:language_interface' - cacheable: false + max-age: 0 diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_row_render_cache.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_row_render_cache.yml index 28a1812c5f8a0eedf6f87ce7f17fcbf8adc9e313..024ddd87187b117e28a93d47cc3b972aa15b0290 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_row_render_cache.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_row_render_cache.yml @@ -500,4 +500,4 @@ display: - 'languages:language_content' - 'languages:language_interface' - 'user.node_grants:view' - cacheable: false + max-age: 0 diff --git a/core/modules/views/views.post_update.php b/core/modules/views/views.post_update.php new file mode 100644 index 0000000000000000000000000000000000000000..5d248a5c740aeea677488dba56b2d2da90f2e2ed --- /dev/null +++ b/core/modules/views/views.post_update.php @@ -0,0 +1,36 @@ +getStorage('view')->loadMultiple(); + + /* @var \Drupal\views\Entity\View[] $views */ + foreach ($views as $view) { + $displays = $view->get('display'); + foreach (array_keys($displays) as $display_id) { + $display =& $view->getDisplay($display_id); + // Unset the cache_metadata key, so all cacheability metadata for the + // display is recalculated. + unset($display['cache_metadata']); + } + $view->save(); + } + +} + +/** + * @} End of "addtogroup updates-8.0.0-beta". + */