You are here

public function SearchApiCachePluginTrait::cacheSet in Search API 8

File

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

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 cacheSet($type) {
  if ($type != 'results') {
    parent::cacheSet($type);
    return;
  }
  $view = $this
    ->getView();
  $data = [
    'result' => $view->result,
    'total_rows' => $view->total_rows ?? 0,
    'current_page' => $view
      ->getCurrentPage(),
    'search_api results' => $this
      ->getQuery()
      ->getSearchApiResults(),
  ];
  $expire = $this
    ->cacheSetMaxAge($type);
  if ($expire !== Cache::PERMANENT) {
    $expire += (int) $view
      ->getRequest()->server
      ->get('REQUEST_TIME');
  }
  $this
    ->getCacheBackend()
    ->set($this
    ->generateResultsKey(), $data, $expire, $this
    ->getCacheTags());
}