Commit cce2380b authored by alexpott's avatar alexpott

Issue #2226613 by damiankloip: Add cache tags to Views data and plugin definition cache entries.

parent 1c11d164
......@@ -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;
......
......@@ -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')));
}
}
......@@ -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;
}
......
......@@ -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));
}
}
......@@ -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;
......
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment