diff --git a/core/modules/field/src/Plugin/views/field/Field.php b/core/modules/field/src/Plugin/views/field/Field.php index f7a2f43..95e3b85 100644 --- a/core/modules/field/src/Plugin/views/field/Field.php +++ b/core/modules/field/src/Plugin/views/field/Field.php @@ -953,7 +953,7 @@ public function isCacheable() { } /** - * @return string[] + * {@inheritdoc} */ public function getCacheContexts() { // @todo what to do about field access? diff --git a/core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php b/core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php index 446e345..0f00779 100644 --- a/core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php +++ b/core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php @@ -103,7 +103,7 @@ public function adminSummary() { * {@inheritdoc} */ public function isCacheable() { - // This filter depends on the current time. + // This filter depends on the current time and therefore is never cacheable. return FALSE; } diff --git a/core/modules/views/src/Entity/View.php b/core/modules/views/src/Entity/View.php index 13a844c..35fa827 100644 --- a/core/modules/views/src/Entity/View.php +++ b/core/modules/views/src/Entity/View.php @@ -303,16 +303,16 @@ public function preSave(EntityStorageInterface $storage) { // @todo Check whether isSyncing is needed. if (!$this->isSyncing()) { - $this->fillCacheInformation(); + $this->fillCacheMetadata(); } } /** - * Fill in all the cache information (cache contexts as cacheablity). + * Fill in all the cache metadata (cache contexts as cacheablity). * * The cache information is stored per view and per display. */ - protected function fillCacheInformation() { + protected function fillCacheMetadata() { $executable = $this->getExecutable(); $current_display = $executable->current_display; @@ -320,7 +320,7 @@ protected function fillCacheInformation() { foreach ($displays as $display_id => $display) { $executable->setDisplay($display_id); - list($display['cache_information']['contexts'], $display['cache_information']['cacheable']) = $executable->getDisplay()->getCacheInformation(); + list($display['cache_information']['contexts'], $display['cache_information']['cacheable']) = $executable->getDisplay()->getCacheMetadata(); // Always include at least the language context as there will be most // probable translatable strings in the view output. $display['cache_information']['contexts'][] = 'cache.context.language'; diff --git a/core/modules/views/src/Plugin/CacheablePluginInterface.php b/core/modules/views/src/Plugin/CacheablePluginInterface.php index 847af59..9cccb56 100644 --- a/core/modules/views/src/Plugin/CacheablePluginInterface.php +++ b/core/modules/views/src/Plugin/CacheablePluginInterface.php @@ -7,14 +7,25 @@ namespace Drupal\views\Plugin; +/** + * Provides information whether and how the specific views plugin is cacheable. + */ interface CacheablePluginInterface { /** + * Returns TRUE if this filter is cacheable at all. + * * @return bool */ public function isCacheable(); /** + * Returns an array of cache contexts, this plugin varies by. + * + * Note: This method is called on views safe time, so you do have the + * configuration available. For example an exposed filter changes its + * cacheability depending on the URL. + * * @return string[] */ public function getCacheContexts(); diff --git a/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php b/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php index d5ca394..6ac55f8 100644 --- a/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php +++ b/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php @@ -1180,6 +1180,7 @@ protected function unpackArgumentValue($force_int = FALSE) { public function isCacheable() { $result = TRUE; + // Asks all sub plugins (argument defaults, argument validator and styles). if (($plugin = $this->getPlugin('argument_default')) && $plugin instanceof CacheablePluginInterface) { $result &= $plugin->isCacheable(); } @@ -1205,6 +1206,7 @@ public function getCacheContexts() { // the information from there. $contexts[] = 'cache.context.url'; + // Asks all sub plugins (argument defaults, argument validator and styles). if (($plugin = $this->getPlugin('argument_default')) && $plugin instanceof CacheablePluginInterface) { $contexts = array_merge($plugin->getCacheContexts(), $contexts); } diff --git a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php index 4741646..526014b 100644 --- a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php @@ -2214,14 +2214,14 @@ public function preExecute() { } /** - * Determines the available cache information from each handler/plugin. + * Determines the available cache metadata from each handler/plugin. * * @return array * Returns an array: * - first value: (boolean) Is the display actually cacheable. * - second value: An array of cache contexts the view output varies by. */ - public function getCacheInformation () { + public function getCacheMetadata () { $cacheable = TRUE; $cache_contexts = [];