Problem/Motivation

When adding cache tags to a view, they show up in the X-Drupal-Cache-Tags header correctly. When invalidating the tags nothing happens. Invalidating the existing (system) cache tag from the view clears the cache tag correctly, but custom cache tags not. Looking in the database the cache tags aren't added to the cache_render table at all, only the existing ones (for example "config:views.view.listing_1 rendered").

Custom cache tag added: custom:view.listing_1.user.{{ raw_arguments.null }}, which shows up in X-Drupal-Cache-Tags correctly like custom:view.listing_1.user.1

Version: Drupal 9.4.5 / Views 9.4.5 / Views Custom Cache Tag: 8.x-1.2

CommentFileSizeAuthor
#7 3322830-cache-tags.patch1021 bytesciprian.stavovei
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

pablovos created an issue. See original summary.

pablovos’s picture

Title: Cache Tags not added to » Cache Tags not added to view
pablovos’s picture

I wrongly assumed that CustomTags would also be added to individual rows but this is not the case. Adding this code to src/Plugin/views/cache/CustomTag.php solved the issue for us:

/**
 * {@inheritdoc}
 */
public function getRowCacheTags(\Drupal\views\ResultRow $row) {
  $tags = parent::getRowCacheTags($row);

  $custom_tags = preg_split('/\r\n|[\r\n]/', $this->options['custom_tag']);
  $custom_tags = array_map('trim', $custom_tags);
  $custom_tags =  array_map(function ($tag){ return $this->view->getStyle()->tokenizeValue($tag, 0);}, $custom_tags);

  $tags = Cache::mergeTags($custom_tags, $tags);

  return $tags;
}
berdir’s picture

haven't really seen that before, I think entity rendered views don't use that, we usually use those. Makes sense, can you create that as a patch or merge request?

ciprian.stavovei made their first commit to this issue’s fork.

ciprian.stavovei’s picture

Status: Active » Needs review
StatusFileSize
new1021 bytes

I also ran into this issue and code from #3 fixed it so I added a PR and a patch for it so that anybody can use it easily.

berdir’s picture

Status: Needs review » Needs work

This has coding standard problems.

A test would be great, basically add an example view to the demo module and then assert it, similar to the existing test.

eduardo morales alberti made their first commit to this issue’s fork.