diff --git a/src/Plugin/views/cache/SearchApiCachePluginTrait.php b/src/Plugin/views/cache/SearchApiCachePluginTrait.php index 71751b6..e11a341 100644 --- a/src/Plugin/views/cache/SearchApiCachePluginTrait.php +++ b/src/Plugin/views/cache/SearchApiCachePluginTrait.php @@ -4,6 +4,7 @@ namespace Drupal\search_api\Plugin\views\cache; use Drupal\Component\Utility\Crypt; use Drupal\Core\Cache\Cache; +use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Cache\Context\CacheContextsManager; use Drupal\search_api\Plugin\views\query\SearchApiQuery; @@ -209,4 +210,15 @@ trait SearchApiCachePluginTrait { throw new SearchApiException('No matching Search API Views query found in view.'); } + /** + * {@inheritdoc} + */ + public function alterCacheMetadata(CacheableMetadata $cache_metadata) { + // When additional access checks are executed, the cache has to vary + // by user. + if (isset($this->view->query->options['skip_access']) && $this->view->query->options['skip_access'] === FALSE) { + $cache_metadata->addCacheContexts(['user']); + } + } + }