00001 <?php 00002 00006 class views_plugin_cache_time extends views_plugin_cache { 00007 function option_definition() { 00008 $options = parent::option_definition(); 00009 $options['results_lifespan'] = array('default' => 3600); 00010 $options['output_lifespan'] = array('default' => 3600); 00011 00012 return $options; 00013 } 00014 00015 function options_form(&$form, &$form_state) { 00016 parent::options_form($form, $form_state); 00017 $options = array(60, 300, 1800, 3600, 21600, 518400); 00018 $options = drupal_map_assoc($options, 'format_interval'); 00019 $options = array(-1 => t('Never cache')) + $options; 00020 00021 $form['results_lifespan'] = array( 00022 '#type' => 'select', 00023 '#title' => t('Query results'), 00024 '#description' => t('The length of time raw query results should be cached.'), 00025 '#options' => $options, 00026 '#default_value' => $this->options['results_lifespan'], 00027 ); 00028 $form['output_lifespan'] = array( 00029 '#type' => 'select', 00030 '#title' => t('Rendered output'), 00031 '#description' => t('The length of time rendered HTML output should be cached.'), 00032 '#options' => $options, 00033 '#default_value' => $this->options['output_lifespan'], 00034 ); 00035 } 00036 00037 function summary_title() { 00038 return format_interval($this->options['results_lifespan'], 1) . '/' . format_interval($this->options['output_lifespan'], 1); 00039 } 00040 00041 function cache_expire($type) { 00042 if ($lifespan = $this->options[$type . '_lifespan']) { 00043 $cutoff = REQUEST_TIME - $lifespan; 00044 return $cutoff; 00045 } 00046 else { 00047 return FALSE; 00048 } 00049 } 00050 00051 function cache_set_expire($type) { 00052 if ($lifespan = $this->options[$type . '_lifespan']) { 00053 return time() + $lifespan; 00054 } 00055 else { 00056 return CACHE_PERMANENT; 00057 } 00058 } 00059 }