Active
Project:
Drupal core
Version:
main
Component:
views.module
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
20 Nov 2018 at 12:33 UTC
Updated:
24 Mar 2026 at 15:13 UTC
Jump to comment: Most recent
Views result cache not containing cache tags from plugins
I've created a sorting plugin that add some cache tags to the view. The display picks up the tag but the cache results don't.
Currently I've written a new plugin that works around this by adding the cache tags on the current display to the cache tags on the query/results.
namespace Drupal\sortable_list\Plugin\views\cache;
use Drupal\Core\Cache\Cache;
use Drupal\views\Plugin\views\cache\Tag;
/**
* Simple caching of query results for Views displays.
* This is a temporary fix for views not adding all cache tags.
*
* @ingroup views_cache_plugins
*
* @ViewsCache(
* id = "tag_with_display_tags",
* title = @Translation("Tag based (display)"),
* help = @Translation("Extends tag plugin. This included a fix for the result cache not containing cache tags from plugins")
* )
*/
class TagWithDisplayTags extends Tag {
/**
* {@inheritdoc}
*/
public function getCacheTags() {
$tags = parent::getCacheTags();
if(isset($this->view->current_display)){
$currentDisplay = $this->view->storage->getDisplay($this->view->current_display);
if(isset($currentDisplay['cache_metadata']['tags'])){
$tags = Cache::mergeTags($tags, $currentDisplay['cache_metadata']['tags']);
}
}
return $tags;
}
}
Comments
Comment #10
smustgrave commentedThis came up as the daily BSI target
Think first steps is to still confirm if this is a bug.
If yes it'll need an issue summary update ot use the standard template. Steps to reproduce, proposed solution, etc.
Will also need some kind of test coverage but not tagging just yet till it's confirmed.