Issue #2222847 by damiankloip: Simplify Views cache tags to just a list tag per entity type.

8.0.x
catch 2014-03-25 20:37:11 +01:00
parent 4e9a885109
commit 0cb6fc701c
3 changed files with 12 additions and 49 deletions

View File

@ -274,7 +274,8 @@ class EntityViewBuilder extends EntityControllerBase implements EntityController
*/
public function resetCache(array $entities = NULL) {
if (isset($entities)) {
$tags = array();
// Always invalidate the ENTITY_TYPE_list tag.
$tags = array($this->entityTypeId . '_list' => TRUE);
foreach ($entities as $entity) {
$id = $entity->id();
$tags[$this->entityTypeId][$id] = $id;

View File

@ -332,41 +332,19 @@ abstract class CachePluginBase extends PluginBase {
* An array fo cache tags based on the current view.
*/
protected function getCacheTags() {
$tags = array();
$id = $this->view->storage->id();
$tags['view'][$id] = $id;
$tags = array('view' => array($id => $id));
$entity_information = $this->view->query->getEntityTableInfo();
if (!empty($entity_information)) {
// Add an ENTITY_TYPE_view tag for each entity type used by this view.
foreach (array_keys($entity_information) as $type) {
$tags[$type . '_view'] = TRUE;
}
// Collect entity IDs if there are view results.
if (!empty($this->view->result)) {
foreach ($this->view->result as $result) {
$type = $result->_entity->getEntityTypeId();
$tags[$type][] = $result->_entity->id();
$tags[$type . '_view_' . $result->_entity->bundle()] = TRUE;
foreach ($result->_relationship_entities as $entity) {
$type = $entity->getEntityTypeId();
$tags[$type][] = $entity->id();
$tags[$type . '_view_' . $entity->bundle()] = TRUE;
}
}
// Add an ENTITY_TYPE_list tag for each entity type used by this view.
foreach (array_keys($entity_information) as $entity_type) {
$tags[$entity_type . '_list'] = TRUE;
}
}
// Filter out any duplicate values from generated tags.
return array_map(function($item) {
return is_array($item) ? array_unique($item) : $item;
}, $tags);
return $tags;
}
}

View File

@ -144,37 +144,21 @@ class CacheTagTest extends PluginTestBase {
$view->destroy();
$view->render();
// Test that invalidating a tag for a different node type, does not
// invalidate the cache.
$cache_plugin = $view->display_handler->getPlugin('cache');
$this->assertTrue($cache_plugin->cacheGet('results'), 'Results cache found.');
$this->assertTrue($cache_plugin->cacheGet('output'), 'Output cache found.');
$this->nodeViewBuilder->resetCache(array($this->article));
$cache_plugin = $view->display_handler->getPlugin('cache');
$this->assertTrue($cache_plugin->cacheGet('results'), 'Results cache found after an article node is invalidated.');
$this->assertTrue($cache_plugin->cacheGet('output'), 'Output cache found after an article node is invalidated.');
$view->destroy();
$view->render();
// Test that saving a node for a different node type, does not invalidate
// the cache.
// Test saving a node not in this view invalidates the cache too.
$cache_plugin = $view->display_handler->getPlugin('cache');
$this->assertTrue($cache_plugin->cacheGet('results'), 'Results cache found.');
$this->assertTrue($cache_plugin->cacheGet('output'), 'Output cache found.');
$this->article->save();
$cache_plugin = $view->display_handler->getPlugin('cache');
$this->assertTrue($cache_plugin->cacheGet('results'), 'Results cache found after an article node is saved.');
$this->assertTrue($cache_plugin->cacheGet('output'), 'Output cache found after an article node is saved.');
$this->assertFalse($cache_plugin->cacheGet('results'), 'Results cache empty after an article node is saved.');
$this->assertFalse($cache_plugin->cacheGet('output'), 'Output cache empty after an article node is saved.');
$view->destroy();
$view->render();
// Test that invalidating a tag for a user, does not invalidate the cache.
// Test that invalidating a tag for a user, does not invalidate the cache,
// as the user entity type will not be contained in the views cache tags.
$cache_plugin = $view->display_handler->getPlugin('cache');
$this->assertTrue($cache_plugin->cacheGet('results'), 'Results cache found.');
$this->assertTrue($cache_plugin->cacheGet('output'), 'Output cache found.');