class views_plugin_cache_time

Simple caching of query results for Views displays.

Hierarchy

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

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

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
views_object::$definition public property Handler's definition.
views_object::$options public property Except for displays, options for the object will be held here. 1
views_object::altered_option_definition public function Collect this handler's option definition and alter them, ready for use.
views_object::construct public function Views handlers use a special construct function. 4
views_object::destroy public function Destructor. 2
views_object::export_option public function 1
views_object::export_options public function
views_object::export_option_always public function Always exports the option, regardless of the default value.
views_object::options Deprecated public function Set default options on this object. 1
views_object::set_default_options public function Set default options.
views_object::set_definition public function Let the handler know what its full definition is.
views_object::unpack_options public function Unpack options over our existing defaults, drilling down into arrays so
that defaults don't get totally blown away.
views_object::unpack_translatable public function Unpack a single option definition.
views_object::unpack_translatables public function Unpacks each handler to store translatable texts.
views_object::_set_option_defaults public function
views_plugin::$display public property The current used views display.
views_plugin::$plugin_name public property The plugin name of this plugin, for example table or full.
views_plugin::$plugin_type public property The plugin type of this plugin, for example style or query.
views_plugin::$view public property The top object of a view. Overrides views_object::$view 1
views_plugin::additional_theme_functions public function Provide a list of additional theme functions for the theme info page.
views_plugin::options_submit public function Handle any special handling on the validate form. 9
views_plugin::plugin_title public function Return the human readable name of the display.
views_plugin::query public function Add anything to the query that we might need to. 7
views_plugin::theme_functions public function Provide a full list of possible theme templates used by this style.
views_plugin::validate public function Validate that the plugin is correct and can be saved. 3
views_plugin_cache::$storage public property Contains all data that should be written/read from cache.
views_plugin_cache::$table public property What table to store data in.
views_plugin_cache::assetDiff protected function Computes the differences between two JS/CSS asset arrays.
views_plugin_cache::cache_flush public function Clear out cached data for a view.
views_plugin_cache::cache_start public function Start caching JavaScript, css and other out of band info. 1
views_plugin_cache::gather_headers public function Gather out of band data, compare it to the start data and store the diff.
views_plugin_cache::get_cache_key public function Returns cache key.
views_plugin_cache::get_output_key public function
views_plugin_cache::get_results_key public function
views_plugin_cache::init public function Initialize the plugin.
views_plugin_cache::post_render public function Post process any rendered data.
views_plugin_cache::restore_headers public function Restore out of band data saved to cache. Copied from Panels.
views_plugin_cache_time::cache_expire public function Determine the expiration time of the cache type, or NULL if no expire. Overrides views_plugin_cache::cache_expire
views_plugin_cache_time::cache_get public function Retrieve data from the cache. Overrides views_plugin_cache::cache_get
views_plugin_cache_time::cache_set public function Save data to the cache. Overrides views_plugin_cache::cache_set
views_plugin_cache_time::cache_set_expire public function Determine expiration time in the cache table of the cache type. Overrides views_plugin_cache::cache_set_expire
views_plugin_cache_time::get_lifespan public function
views_plugin_cache_time::options_form public function Provide a form to edit options for this plugin. Overrides views_plugin::options_form
views_plugin_cache_time::options_validate public function Validate the options form. Overrides views_plugin::options_validate
views_plugin_cache_time::option_definition public function Information about options for all kinds of purposes will be held here. Overrides views_object::option_definition
views_plugin_cache_time::summary_title public function Return a string to display as the clickable title for the
access control.
Overrides views_plugin_cache::summary_title