Hello,

Using entityqueue with views (relationship + sort), when I update the queue, for example adding items, the view cache is not regenerated.

You can see the configuration on this repository: https://github.com/Drupal-FR/socle-drupalcampfr

I use entityqueue for sorting news on the homepage.

I currently don't have the time to investigate sorry.

Thanks for any help.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Grimreaper created an issue. See original summary.

Grimreaper’s picture

Issue summary: View changes

Editing git repository URL.

krlucas’s picture

There are two potential caches that EntityQueue needs to be aware of, the Views result cache (the "Cache" setting in the View's UI) and the Drupal render cache.

I haven't been able to successfully figure out where the Views relationship or sort plug-ins for entityqueue would provide the proper cache tags.

But I did create a hook in a custom module that adds cache tags to the View's render array so that the render cache is invalidated when an entityqueue is saved. For this to work the View has to be configured with (results) Cache = None.


use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\cache\CachePluginBase;
use Drupal\entityqueue\Plugin\views\relationship\EntityQueueRelationship;

/**
 * Implements hook_views_post_render().
 */
function XXXXXX_views_post_render(ViewExecutable $view, &$output, CachePluginBase $cache) {
  // This is a workaround for https://www.drupal.org/node/2686623.
  // Adds the entityqueue cache tag to the render array. Note that this does
  // not effect the Views results cache (the "Cache" setting in the views admin)
  // so that has to be disabled on the view for this to work.
  if (!empty($view->relationship)) {
    foreach ($view->relationship as $relationship) {
      if ($relationship instanceof EntityQueueRelationship) {
        $output['#cache']['tags'][] = 'entity_subqueue:' . $relationship->options['limit_queue'];
      }
    }
  }
}
amateescu’s picture

Issue tags: +D8 cache tags
FileSize
3.33 KB

For this to work the View has to be configured with (results) Cache = None.

That's because Views cache plugins do not take into account possible cache tags that could be provided by other views handlers (relationship, filter, etc.) :/ I opened a core issue for this #2710679: Views handlers should be able to add cache tags to the views results cache and implemented a workaround for now: invalidate the <target_entity_type>_list cache tag when a subqueue is updated.

  • amateescu committed 50ec8db on 8.x-1.x
    Issue #2686623 by amateescu: Empty views cache when queue is updated
    
amateescu’s picture

Status: Active » Fixed

Committed and pushed to 8.x-1.x.

sdstyles’s picture

Status: Fixed » Needs review
FileSize
682 bytes
36.73 KB

The method $target_entity_type->getListCacheTags() already returns an array of strings, so we don't need to force it to be an array, as result this throws an error in mergeTags() because tag is an array not a string, see the screenshot with error.

  • amateescu committed a2f8e41 on 8.x-1.x authored by sdstyles
    Issue #2686623 followup by sdstyles: Empty views cache when queue is...
amateescu’s picture

Status: Needs review » Fixed

Oops, that's right :) Committed the followup patch, thanks!

Grimreaper’s picture

Issue summary: View changes

Thanks for the patches. It works well.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.