diff --git a/core/modules/rest/src/Plugin/views/display/RestExport.php b/core/modules/rest/src/Plugin/views/display/RestExport.php index 5392e48..4fb5405 100644 --- a/core/modules/rest/src/Plugin/views/display/RestExport.php +++ b/core/modules/rest/src/Plugin/views/display/RestExport.php @@ -302,17 +302,13 @@ public function render() { $build['#suffix'] = ''; } - $build += ['#cache' => []]; - $build['#cache'] += [ - 'tags' => [], - 'max-age' => CacheBackendInterface::CACHE_PERMANENT, - ]; + // Defaults for bubbleable rendering metadata. + $elements['#cache']['tags'] = isset($elements['#cache']['tags']) ? $elements['#cache']['tags'] : array(); + $elements['#cache']['max-age'] = isset($elements['#cache']['max-age']) ? $elements['#cache']['max-age'] : Cache::PERMANENT; /** @var \Drupal\views\Plugin\views\cache\CachePluginBase $cache */ $cache = $this->getPlugin('cache'); - // If the output is a render array, add cache tags, regardless of whether - // caching is enabled or not; cache tags must always be set. $build['#cache']['tags'] = Cache::mergeTags($build['#cache']['tags'], $cache->getCacheTags()); $build['#cache']['max-age'] = Cache::mergeMaxAges($build['#cache']['max-age'], $cache->getCacheMaxAge()); diff --git a/core/modules/rest/src/Tests/Views/StyleSerializerTest.php b/core/modules/rest/src/Tests/Views/StyleSerializerTest.php index a8b2dee..137e8f0 100644 --- a/core/modules/rest/src/Tests/Views/StyleSerializerTest.php +++ b/core/modules/rest/src/Tests/Views/StyleSerializerTest.php @@ -80,7 +80,7 @@ public function testSerializerResponses() { $this->assertResponse(200); $this->assertCacheTags($view->getCacheTags()); // @todo Due to https://www.drupal.org/node/2352009 we can't yet test the - // propagation of cache tags. + // propagation of cache max-age. // Test the http Content-type. $headers = $this->drupalGetHeaders(); diff --git a/core/modules/system/src/Tests/Cache/AssertPageCacheContextsAndTagsTrait.php b/core/modules/system/src/Tests/Cache/AssertPageCacheContextsAndTagsTrait.php index f1c34af..6841293 100644 --- a/core/modules/system/src/Tests/Cache/AssertPageCacheContextsAndTagsTrait.php +++ b/core/modules/system/src/Tests/Cache/AssertPageCacheContextsAndTagsTrait.php @@ -99,7 +99,7 @@ protected function assertCacheContexts(array $expected_contexts) { protected function assertCacheMaxAge($max_age) { $cache_control_header = $this->drupalGetHeader('Cache-Control'); if (strpos($cache_control_header, 'max-age:' . $max_age) === FALSE) { - debug('Expected max_age:' . $max_age . '; Response max_age:' . $cache_control_header); + debug('Expected max-age:' . $max_age . '; Response max-age:' . $cache_control_header); } $this->assertTrue(strpos($cache_control_header, 'max-age:' . $max_age)); } diff --git a/core/modules/views/src/Plugin/views/cache/CachePluginBase.php b/core/modules/views/src/Plugin/views/cache/CachePluginBase.php index d850d4f..a929557 100644 --- a/core/modules/views/src/Plugin/views/cache/CachePluginBase.php +++ b/core/modules/views/src/Plugin/views/cache/CachePluginBase.php @@ -379,7 +379,7 @@ public function getCacheTags() { */ public function getCacheMaxAge() { $max_age = $this->getDefaultCacheMaxAge(); - $max_age = Cache::mergeMaxAges($max_age, $this->view->getQuery()->getCacheMaxAges()); + $max_age = Cache::mergeMaxAges($max_age, $this->view->getQuery()->getCacheMaxAge()); return $max_age; } diff --git a/core/modules/views/src/Plugin/views/query/QueryPluginBase.php b/core/modules/views/src/Plugin/views/query/QueryPluginBase.php index 03a7f37..857c0c7 100644 --- a/core/modules/views/src/Plugin/views/query/QueryPluginBase.php +++ b/core/modules/views/src/Plugin/views/query/QueryPluginBase.php @@ -345,7 +345,7 @@ public function getCacheTags() { /** * {@inheritdoc} */ - public function getCacheMaxAges() { + public function getCacheMaxAge() { return Cache::PERMANENT; } diff --git a/core/modules/views/src/Plugin/views/query/Sql.php b/core/modules/views/src/Plugin/views/query/Sql.php index 6d98239..e312970 100644 --- a/core/modules/views/src/Plugin/views/query/Sql.php +++ b/core/modules/views/src/Plugin/views/query/Sql.php @@ -1563,8 +1563,8 @@ public function getCacheTags() { /** * {@inheritdoc} */ - public function getCacheMaxAges() { - $max_age = parent::getCacheMaxAges(); + public function getCacheMaxAge() { + $max_age = parent::getCacheMaxAge(); foreach ($this->getAllEntities() as $entity) { $max_age = Cache::mergeMaxAges($max_age, $entity->getCacheMaxAge()); } diff --git a/core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php b/core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php index 77b9eaf..feb3ce2 100644 --- a/core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php +++ b/core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php @@ -100,7 +100,7 @@ public function testGetCacheMaxAge() { $entity = $prophecy->reveal(); $row->_relationship_entities[] = $entity; - $this->assertEquals(10, $query->getCacheMaxAges()); + $this->assertEquals(10, $query->getCacheMaxAge()); } }