class SearchApiViewsContentCache in Search API 7
Plugin class for caching Search API views, with additional invalidation.
Hierarchy
- class \views_object
- class \views_plugin
- class \views_plugin_cache
- class \views_plugin
Expanded class hierarchy of SearchApiViewsContentCache
1 string reference to 'SearchApiViewsContentCache'
- search_api_views_views_plugins in contrib/
search_api_views/ search_api_views.views.inc - Implements hook_views_plugins().
File
- contrib/
search_api_views/ includes/ plugin_content_cache.inc, line 11 - Contains the SearchApiViewsContentCache class.
View source
class SearchApiViewsContentCache extends views_content_cache_plugin_cache {
/**
* Static cache for get_results_key().
*
* @var string
*/
protected $_results_key = NULL;
/**
* Static cache for getSearchApiQuery().
*
* @var SearchApiQueryInterface
*/
protected $search_api_query = NULL;
/**
* Overrides views_plugin_cache::cache_set().
*
* Also stores Search API's internal search results.
*/
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));
}
/**
* Overrides views_plugin_cache::cache_get().
*
* Additionally stores successfully retrieved results with
* search_api_current_search().
*/
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;
}
/**
* Overrides views_plugin_cache::get_cache_key().
*
* Use the Search API query as the main source for the key. Note that in
* Views < 3.8, this method does not exist.
*/
public function get_cache_key($key_data = array()) {
global $user;
if (!isset($this->_results_key)) {
$query = $this
->getSearchApiQuery();
$query
->preExecute();
$key_data += array(
'query' => $query,
'roles' => array_keys($user->roles),
'super-user' => $user->uid == 1,
// special caching for super user.
'language' => $GLOBALS['language']->language,
'base_url' => $GLOBALS['base_url'],
'offset' => $this->view
->get_current_page() . '*' . $this->view
->get_items_per_page() . '+' . $this->view
->get_offset(),
);
// Not sure what gets passed in exposed_info, so better include it. All
// other parameters used in the parent method are already reflected in the
// Search API query object we use.
if (isset($_GET['exposed_info'])) {
$key_data['exposed_info'] = $_GET['exposed_info'];
}
}
$key = drupal_hash_base64(serialize($key_data));
return $key;
}
/**
* Overrides views_plugin_cache::get_results_key().
*
* This is unnecessary for Views >= 3.8.
*/
public function get_results_key() {
if (!isset($this->_results_key)) {
$this->_results_key = $this->view->name . ':' . $this->display->id . ':results:' . $this
->get_cache_key();
}
return $this->_results_key;
}
/**
* Retrieves the Search API query object associated with the current view.
*
* @return SearchApiQueryInterface|null
* The Search API query object associated with the current view; or NULL if
* there is none.
*/
protected function getSearchApiQuery() {
if (!isset($this->search_api_query)) {
$this->search_api_query = FALSE;
if (isset($this->view->query) && $this->view->query instanceof SearchApiViewsQuery) {
$this->search_api_query = $this->view->query
->getSearchApiQuery();
}
}
return $this->search_api_query ? $this->search_api_query : NULL;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SearchApiViewsContentCache:: |
protected | property | Static cache for getSearchApiQuery(). | |
SearchApiViewsContentCache:: |
protected | property | Static cache for get_results_key(). | |
SearchApiViewsContentCache:: |
public | function |
Overrides views_plugin_cache::cache_get(). Overrides views_plugin_cache:: |
|
SearchApiViewsContentCache:: |
public | function |
Overrides views_plugin_cache::cache_set(). Overrides views_plugin_cache:: |
|
SearchApiViewsContentCache:: |
protected | function | Retrieves the Search API query object associated with the current view. | |
SearchApiViewsContentCache:: |
public | function |
Overrides views_plugin_cache::get_cache_key(). Overrides views_plugin_cache:: |
|
SearchApiViewsContentCache:: |
public | function |
Overrides views_plugin_cache::get_results_key(). Overrides views_plugin_cache:: |
|
views_content_cache_plugin_cache:: |
function |
Return the expiry time for this cache plugin. Overrides views_plugin_cache:: |
||
views_content_cache_plugin_cache:: |
function |
Determine expiration time in the cache table of the cache type
or CACHE_PERMANENT if item shouldn't be removed automatically from cache. Overrides views_plugin_cache:: |
||
views_content_cache_plugin_cache:: |
function |
Provide a form to edit options for this plugin. Overrides views_plugin:: |
||
views_content_cache_plugin_cache:: |
function | |||
views_content_cache_plugin_cache:: |
function |
Information about options for all kinds of purposes will be held here. Overrides views_object:: |
||
views_content_cache_plugin_cache:: |
function |
Return a string to display as the clickable title for the
access control. Overrides views_plugin_cache:: |
||
views_object:: |
public | property | Handler's definition. | |
views_object:: |
public | property | Except for displays, options for the object will be held here. | 1 |
views_object:: |
function | Collect this handler's option definition and alter them, ready for use. | ||
views_object:: |
public | function | Views handlers use a special construct function. | 4 |
views_object:: |
public | function | Destructor. | 2 |
views_object:: |
public | function | 1 | |
views_object:: |
public | function | ||
views_object:: |
public | function | Always exports the option, regardless of the default value. | |
views_object:: |
public | function | Set default options on this object. | 1 |
views_object:: |
public | function | Set default options. | |
views_object:: |
public | function | Let the handler know what its full definition is. | |
views_object:: |
public | function | Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away. | |
views_object:: |
public | function | Unpack a single option definition. | |
views_object:: |
public | function | Unpacks each handler to store translatable texts. | |
views_object:: |
public | function | ||
views_plugin:: |
public | property | The current used views display. | |
views_plugin:: |
public | property | The plugin name of this plugin, for example table or full. | |
views_plugin:: |
public | property | The plugin type of this plugin, for example style or query. | |
views_plugin:: |
public | property |
The top object of a view. Overrides views_object:: |
1 |
views_plugin:: |
public | function | Provide a list of additional theme functions for the theme info page. | |
views_plugin:: |
public | function | Handle any special handling on the validate form. | 9 |
views_plugin:: |
public | function | Validate the options form. | 10 |
views_plugin:: |
public | function | Return the human readable name of the display. | |
views_plugin:: |
public | function | Add anything to the query that we might need to. | 7 |
views_plugin:: |
public | function | Provide a full list of possible theme templates used by this style. | |
views_plugin:: |
public | function | Validate that the plugin is correct and can be saved. | 3 |
views_plugin_cache:: |
public | property | Contains all data that should be written/read from cache. | |
views_plugin_cache:: |
public | property | What table to store data in. | |
views_plugin_cache:: |
protected | function | Computes the differences between two JS/CSS asset arrays. | |
views_plugin_cache:: |
public | function | Clear out cached data for a view. | |
views_plugin_cache:: |
public | function | Start caching JavaScript, css and other out of band info. | 1 |
views_plugin_cache:: |
public | function | Gather out of band data, compare it to the start data and store the diff. | |
views_plugin_cache:: |
public | function | ||
views_plugin_cache:: |
public | function | Initialize the plugin. | |
views_plugin_cache:: |
public | function | Post process any rendered data. | |
views_plugin_cache:: |
public | function | Restore out of band data saved to cache. Copied from Panels. |