public function SearchApiViewsContentCache::cache_get in Search API 7
Overrides views_plugin_cache::cache_get().
Additionally stores successfully retrieved results with search_api_current_search().
Overrides views_plugin_cache::cache_get
File
- contrib/
search_api_views/ includes/ plugin_content_cache.inc, line 58 - Contains the SearchApiViewsContentCache class.
Class
- SearchApiViewsContentCache
- Plugin class for caching Search API views, with additional invalidation.
Code
public function cache_get($type) {
if ($type != 'results') {
return parent::cache_get($type);
}
// Values to set: $view->result, $view->total_rows, $view->execute_time,
// $view->current_page.
if ($cache = cache_get($this
->get_results_key(), $this->table)) {
$cutoff = $this
->cache_expire($type);
if (!$cutoff || $cache->created > $cutoff) {
$this->view->result = $cache->data['result'];
$this->view->total_rows = $cache->data['total_rows'];
$this->view
->set_current_page($cache->data['current_page']);
$this->view->execute_time = 0;
// Trick Search API into believing a search happened, to make facetting
// et al. work.
$query = $this
->getSearchApiQuery();
search_api_current_search($query
->getOption('search id'), $query, $cache->data['search_api results']);
return TRUE;
}
}
return FALSE;
}