diff --git a/core/modules/views/lib/Drupal/views/Plugin/ViewsHandlerManager.php b/core/modules/views/lib/Drupal/views/Plugin/ViewsHandlerManager.php index 3f13901b8a74b9162257d4d6abeb8c9cbea0ea26..79f757b3cddbc2caf833acee539e22f606efead5 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/ViewsHandlerManager.php +++ b/core/modules/views/lib/Drupal/views/Plugin/ViewsHandlerManager.php @@ -57,7 +57,7 @@ public function __construct($handler_type, \Traversable $namespaces, ViewsData $ $plugin_definition_annotation_name = 'Drupal\views\Annotation\Views' . Container::camelize($handler_type); parent::__construct("Plugin/views/$handler_type", $namespaces, $module_handler, $plugin_definition_annotation_name); - $this->setCacheBackend($cache_backend, $language_manager, "views:$handler_type"); + $this->setCacheBackend($cache_backend, $language_manager, "views:$handler_type", array('extension' => array(TRUE, 'views'))); $this->viewsData = $views_data; $this->handlerType = $handler_type; diff --git a/core/modules/views/lib/Drupal/views/Plugin/ViewsPluginManager.php b/core/modules/views/lib/Drupal/views/Plugin/ViewsPluginManager.php index e03f3b72b028858f479e17eb8dc31dfae09e3ff1..f4f4f0e52951c7910816dab2e0f18a1205f41bf7 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/ViewsPluginManager.php +++ b/core/modules/views/lib/Drupal/views/Plugin/ViewsPluginManager.php @@ -44,7 +44,7 @@ public function __construct($type, \Traversable $namespaces, CacheBackendInterfa ); $this->alterInfo('views_plugins_' . $type); - $this->setCacheBackend($cache_backend, $language_manager, "views:{$type}_plugins"); + $this->setCacheBackend($cache_backend, $language_manager, "views:{$type}_plugins", array('extension' => array(TRUE, 'views'))); } } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php index d6fe40a7f0927479f0e972a03a381e65e416196c..2777f7a18567c4c5be464fbc1091b658532cdf40 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php @@ -8,6 +8,7 @@ namespace Drupal\views\Plugin\views\display; use Drupal\Component\Utility\String; +use Drupal\Core\Cache\Cache; use Drupal\Core\Language\Language; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Theme\Registry; @@ -165,7 +166,8 @@ public function initDisplay(ViewExecutable $view, array &$display, array &$optio } else { $this->unpackOptions($this->options, $options); - \Drupal::cache('data')->set($cid, $this->options); + $id = $this->view->storage->id(); + \Drupal::cache('data')->set($cid, $this->options, Cache::PERMANENT, array('extension' => array(TRUE, 'views'), 'view' => array($id => $id))); } static::$unpackOptions[$cid] = $this->options; } diff --git a/core/modules/views/lib/Drupal/views/ViewsData.php b/core/modules/views/lib/Drupal/views/ViewsData.php index a1e2da420abc20659d5352aabf1011d3811e9a3e..3fccb8fa66c7ab684ffd22e7271836b937cda799 100644 --- a/core/modules/views/lib/Drupal/views/ViewsData.php +++ b/core/modules/views/lib/Drupal/views/ViewsData.php @@ -7,10 +7,10 @@ namespace Drupal\views; +use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Language\Language; use Drupal\Core\Language\LanguageManagerInterface; /** @@ -177,7 +177,7 @@ protected function cacheGet($cid) { * The data that will be cached. */ protected function cacheSet($cid, $data) { - return $this->cacheBackend->set($this->prepareCid($cid), $data); + return $this->cacheBackend->set($this->prepareCid($cid), $data, Cache::PERMANENT, array('views_data' => TRUE, 'extension' => array(TRUE, 'views'))); } /** @@ -287,6 +287,6 @@ public function fetchBaseTables() { public function clear() { $this->storage = array(); $this->fullyLoaded = FALSE; - $this->cacheBackend->deleteAll(); + Cache::deleteTags(array('views_data' => TRUE)); } } diff --git a/core/modules/views/tests/Drupal/views/Tests/ViewsDataTest.php b/core/modules/views/tests/Drupal/views/Tests/ViewsDataTest.php index 2d49c2f7123ab4d140b8e19c8ee493ab36e0ad47..f74e56efe9a7bb1538b5d8e8371d18a20ac24fc1 100644 --- a/core/modules/views/tests/Drupal/views/Tests/ViewsDataTest.php +++ b/core/modules/views/tests/Drupal/views/Tests/ViewsDataTest.php @@ -71,6 +71,7 @@ public static function getInfo() { */ protected function setUp() { $this->cacheBackend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); + $this->getContainerWithCacheBins($this->cacheBackend); $configs = array(); $configs['views.settings']['skip_cache'] = FALSE; diff --git a/core/modules/views/views.module b/core/modules/views/views.module index 82507344f2faad9617060ba32156282d0479186d..9d6e4af08c30d62fec5353e8ad1935a3f9c4fc9f 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -535,8 +535,7 @@ function views_field_instance_config_create(FieldInstanceConfigInterface $field_ * Implements hook_ENTITY_TYPE_update() for 'field_instance_config'. */ function views_field_instance_config_update(FieldInstanceConfigInterface $field_instance) { - // @todo: Is this necessary? Use cache tags to only delete Views' cache data? - \Drupal::cache('discovery')->deleteAll(); + Cache::deleteTags(array('extension' => 'views')); \Drupal::cache('render')->deleteAll(); } @@ -544,8 +543,7 @@ function views_field_instance_config_update(FieldInstanceConfigInterface $field_ * Implements hook_ENTITY_TYPE_delete() for 'field_instance_config'. */ function views_field_instance_config_delete(FieldInstanceConfigInterface $field_instance) { - // @todo: Is this necessary? Use cache tags to only delete Views' cache data? - \Drupal::cache('discovery')->deleteAll(); + Cache::deleteTags(array('extension' => 'views')); \Drupal::cache('render')->deleteAll(); } @@ -553,12 +551,8 @@ function views_field_instance_config_delete(FieldInstanceConfigInterface $field_ * Invalidate the views cache, forcing a rebuild on the next grab of table data. */ function views_invalidate_cache() { - // Clear Views' info cache entries. - // @todo: Use cache tags? - \Drupal::cache('discovery')->deleteAll(); - - // Clear the page and block cache. - Cache::deleteTags(array('content' => TRUE)); + // Clear the page and block cache and Views' info cache entries. + Cache::deleteTags(array('content' => TRUE, 'extension' => 'views')); // Set the menu as needed to be rebuilt. \Drupal::service('router.builder')->setRebuildNeeded();