You are here

public function SearchApiViewsContentCache::cache_set in Search API 7

Overrides views_plugin_cache::cache_set().

Also stores Search API's internal search results.

Overrides views_plugin_cache::cache_set

File

contrib/search_api_views/includes/plugin_content_cache.inc, line 32
Contains the SearchApiViewsContentCache class.

Class

SearchApiViewsContentCache
Plugin class for caching Search API views, with additional invalidation.

Code

public function cache_set($type) {
  if ($type != 'results') {
    return parent::cache_set($type);
  }
  $cid = $this
    ->get_results_key();
  $results = NULL;
  $query_plugin = $this->view->query;
  if ($query_plugin instanceof SearchApiViewsQuery) {
    $results = $query_plugin
      ->getSearchApiResults();
  }
  $data = array(
    'result' => $this->view->result,
    'total_rows' => isset($this->view->total_rows) ? $this->view->total_rows : 0,
    'current_page' => $this->view
      ->get_current_page(),
    'search_api results' => $results,
  );
  cache_set($cid, $data, $this->table, $this
    ->cache_set_expire($type));
}