class views_plugin_cache_time in Views (for Drupal 7) 7.3
Same name and namespace in other branches
- 6.3 plugins/views_plugin_cache_time.inc \views_plugin_cache_time
- 6.2 plugins/views_plugin_cache_time.inc \views_plugin_cache_time
Simple caching of query results for Views displays.
Hierarchy
- class \views_object
- class \views_plugin
- class \views_plugin_cache
- class \views_plugin_cache_time
- class \views_plugin_cache
- class \views_plugin
Expanded class hierarchy of views_plugin_cache_time
Related topics
1 string reference to 'views_plugin_cache_time'
- views_views_plugins in includes/
plugins.inc - Implements hook_views_plugins().
File
- plugins/
views_plugin_cache_time.inc, line 13 - Definition of views_plugin_cache_time.
View source
class views_plugin_cache_time extends views_plugin_cache {
/**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition();
$options['results_lifespan'] = array(
'default' => 3600,
);
$options['results_lifespan_custom'] = array(
'default' => 0,
);
$options['output_lifespan'] = array(
'default' => 3600,
);
$options['output_lifespan_custom'] = array(
'default' => 0,
);
return $options;
}
/**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$options = array(
60,
300,
1800,
3600,
21600,
518400,
);
$options = drupal_map_assoc($options, 'format_interval');
$options = array(
-1 => t('Never cache'),
) + $options + array(
'custom' => t('Custom'),
);
$form['results_lifespan'] = array(
'#type' => 'select',
'#title' => t('Query results'),
'#description' => t('The length of time raw query results should be cached.'),
'#options' => $options,
'#default_value' => $this->options['results_lifespan'],
);
$form['results_lifespan_custom'] = array(
'#type' => 'textfield',
'#title' => t('Seconds'),
'#size' => '25',
'#maxlength' => '30',
'#description' => t('Length of time in seconds raw query results should be cached.'),
'#default_value' => $this->options['results_lifespan_custom'],
'#process' => array(
'ctools_dependent_process',
),
'#dependency' => array(
'edit-cache-options-results-lifespan' => array(
'custom',
),
),
);
$form['output_lifespan'] = array(
'#type' => 'select',
'#title' => t('Rendered output'),
'#description' => t('The length of time rendered HTML output should be cached.'),
'#options' => $options,
'#default_value' => $this->options['output_lifespan'],
);
$form['output_lifespan_custom'] = array(
'#type' => 'textfield',
'#title' => t('Seconds'),
'#size' => '25',
'#maxlength' => '30',
'#description' => t('Length of time in seconds rendered HTML output should be cached.'),
'#default_value' => $this->options['output_lifespan_custom'],
'#process' => array(
'ctools_dependent_process',
),
'#dependency' => array(
'edit-cache-options-output-lifespan' => array(
'custom',
),
),
);
}
/**
* {@inheritdoc}
*/
public function options_validate(&$form, &$form_state) {
$custom_fields = array(
'output_lifespan',
'results_lifespan',
);
foreach ($custom_fields as $field) {
if ($form_state['values']['cache_options'][$field] == 'custom' && !is_numeric($form_state['values']['cache_options'][$field . '_custom'])) {
form_error($form[$field . '_custom'], t('Custom time values must be numeric.'));
}
}
}
/**
* {@inheritdoc}
*/
public function summary_title() {
$results_lifespan = $this
->get_lifespan('results');
$output_lifespan = $this
->get_lifespan('output');
return format_interval($results_lifespan, 1) . '/' . format_interval($output_lifespan, 1);
}
/**
* {@inheritdoc}
*/
public function get_lifespan($type) {
$lifespan = $this->options[$type . '_lifespan'] == 'custom' ? $this->options[$type . '_lifespan_custom'] : $this->options[$type . '_lifespan'];
return $lifespan;
}
/**
* {@inheritdoc}
*/
public function cache_expire($type) {
$lifespan = $this
->get_lifespan($type);
if ($lifespan) {
$cutoff = REQUEST_TIME - $lifespan;
return $cutoff;
}
else {
return FALSE;
}
}
/**
* {@inheritdoc}
*/
public function cache_set_expire($type) {
$lifespan = $this
->get_lifespan($type);
if ($lifespan) {
return time() + $lifespan;
}
else {
return CACHE_PERMANENT;
}
}
/**
* {@inheritdoc}
*/
public function cache_set($type) {
$lifespan = $this
->get_lifespan($type);
if ($lifespan >= 0) {
parent::cache_set($type);
}
}
/**
* {@inheritdoc}
*/
public function cache_get($type) {
$lifespan = $this
->get_lifespan($type);
if ($lifespan >= 0) {
return parent::cache_get($type);
}
else {
return FALSE;
}
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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 | 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 | Returns cache key. | |
views_plugin_cache:: |
public | function | ||
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. | |
views_plugin_cache_time:: |
public | function |
Determine the expiration time of the cache type, or NULL if no expire. Overrides views_plugin_cache:: |
|
views_plugin_cache_time:: |
public | function |
Retrieve data from the cache. Overrides views_plugin_cache:: |
|
views_plugin_cache_time:: |
public | function |
Save data to the cache. Overrides views_plugin_cache:: |
|
views_plugin_cache_time:: |
public | function |
Determine expiration time in the cache table of the cache type. Overrides views_plugin_cache:: |
|
views_plugin_cache_time:: |
public | function | ||
views_plugin_cache_time:: |
public | function |
Provide a form to edit options for this plugin. Overrides views_plugin:: |
|
views_plugin_cache_time:: |
public | function |
Validate the options form. Overrides views_plugin:: |
|
views_plugin_cache_time:: |
public | function |
Information about options for all kinds of purposes will be held here. Overrides views_object:: |
|
views_plugin_cache_time:: |
public | function |
Return a string to display as the clickable title for the
access control. Overrides views_plugin_cache:: |