You are here

public function SearchApiCachePluginTrait::generateResultsKey in Search API 8

2 calls to SearchApiCachePluginTrait::generateResultsKey()
SearchApiCachePluginTrait::cacheGet in src/Plugin/views/cache/SearchApiCachePluginTrait.php
SearchApiCachePluginTrait::cacheSet in src/Plugin/views/cache/SearchApiCachePluginTrait.php

File

src/Plugin/views/cache/SearchApiCachePluginTrait.php, line 174

Class

SearchApiCachePluginTrait
Provides a trait to use in Views cache plugins for Search API queries.

Namespace

Drupal\search_api\Plugin\views\cache

Code

public function generateResultsKey() {
  if (!isset($this->resultsKey)) {
    $this
      ->getQuery()
      ->getSearchApiQuery()
      ->preExecute();
    $view = $this
      ->getView();
    $build_info = $view->build_info;
    $key_data = [
      'build_info' => $build_info,
      'pager' => [
        'page' => $view
          ->getCurrentPage(),
        'items_per_page' => $view
          ->getItemsPerPage(),
        'offset' => $view
          ->getOffset(),
      ],
    ];

    // Vary the results key by the cache contexts of the display handler.
    // These cache contexts are calculated when the view is saved in the Views
    // UI and stored in the view config entity.
    $display_handler_cache_contexts = $this->displayHandler
      ->getCacheMetadata()
      ->getCacheContexts();
    $key_data += $this
      ->getCacheContextsManager()
      ->convertTokensToKeys($display_handler_cache_contexts)
      ->getKeys();
    $this->resultsKey = $view->storage
      ->id() . ':' . $this->displayHandler->display['id'] . ':results:' . Crypt::hashBase64(serialize($key_data));
  }
  return $this->resultsKey;
}