class views_plugin_cache_time

  1. 3.x plugins/views_plugin_cache_time.inc views_plugin_cache_time
  2. 2.x plugins/views_plugin_cache_time.inc 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'

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 {
  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;
  }

  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('form_process_select', '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('form_process_select', 'ctools_dependent_process'),
      '#dependency' => array(
        'edit-cache-options-output-lifespan' => array('custom'),
      ),
    );
  }

  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.'));
      }
    }
  }

  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);
  }

  function get_lifespan($type) {
    $lifespan = $this->options[$type . '_lifespan'] == 'custom' ? $this->options[$type . '_lifespan_custom'] : $this->options[$type . '_lifespan'];
    return $lifespan;
  }

  function cache_expire($type) {
    $lifespan = $this->get_lifespan($type);
    if ($lifespan) {
      $cutoff = REQUEST_TIME - $lifespan;
      return $cutoff;
    }
    else {
      return FALSE;
    }
  }

  function cache_set_expire($type) {
    $lifespan = $this->get_lifespan($type);
    if ($lifespan) {
      return time() + $lifespan;
    }
    else {
      return CACHE_PERMANENT;
    }
  }
}

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
views_object::construct function Views handlers use a special construct function so that we can more easily construct them with variable arguments.
views_object::destroy function
views_object::export_option function
views_object::export_options function
views_object::export_option_always function Always exports the option, regardless of the default value.
views_object::options Deprecated function Set default options on this object. Called by the constructor in a complex chain to deal with backward compatibility.
views_object::set_default_options function Set default options. For backward compatibility, it sends the options array; this is a feature that will likely disappear at some point.
views_object::set_definition function Let the handler know what its full definition is.
views_object::unpack_options function Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away.
views_object::unpack_translatable function Unpack a single option definition.
views_object::unpack_translatables function Unpacks each handler to store translatable texts.
views_object::_set_option_defaults function
views_plugin::additional_theme_functions function Provide a list of additional theme functions for the theme information page
views_plugin::options_submit function Handle any special handling on the validate form.
views_plugin::plugin_title function Return the human readable name of the display.
views_plugin::query function Add anything to the query that we might need to.
views_plugin::theme_functions function Provide a full list of possible theme templates used by this style.
views_plugin::validate function Validate that the plugin is correct and can be saved.
views_plugin_cache::cache_flush function Clear out cached data for a view.
views_plugin_cache::cache_get function Retrieve data from the cache.
views_plugin_cache::cache_set function Save data to the cache.
views_plugin_cache::cache_start function Start caching javascript, css and other out of band info.
views_plugin_cache::gather_headers function Gather out of band data, compare it to what we started with and store the difference.
views_plugin_cache::get_output_key function
views_plugin_cache::get_results_key function
views_plugin_cache::init function Initialize the plugin.
views_plugin_cache::post_render function Post process any rendered data.
views_plugin_cache::restore_headers function Restore out of band data saved to cache. Copied from Panels.
views_plugin_cache_time::cache_expire 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_set_expire 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::cache_set_expire
views_plugin_cache_time::get_lifespan function
views_plugin_cache_time::options_form function Provide a form to edit options for this plugin. Overrides views_plugin::options_form
views_plugin_cache_time::options_validate function Validate the options form. Overrides views_plugin::options_validate
views_plugin_cache_time::option_definition function Information about options for all kinds of purposes will be held here. @code 'option_name' => array( Overrides views_object::option_definition
views_plugin_cache_time::summary_title function Return a string to display as the clickable title for the access control. Overrides views_plugin_cache::summary_title