[177a560] | 1 | <?php |
---|
| 2 | |
---|
| 3 | /** |
---|
| 4 | * Simple caching of query results for Views displays. |
---|
| 5 | */ |
---|
| 6 | class views_plugin_cache_time extends views_plugin_cache { |
---|
| 7 | function option_defaults(&$options) { |
---|
| 8 | $options['results_lifespan'] = 3600; |
---|
| 9 | $options['output_lifespan'] = 3600; |
---|
| 10 | } |
---|
| 11 | |
---|
| 12 | function options_form(&$form, &$form_state) { |
---|
| 13 | $options = array(60, 300, 1800, 3600, 21600, 518400); |
---|
| 14 | $options = drupal_map_assoc($options, 'format_interval'); |
---|
| 15 | $options = array(-1 => t('Never cache')) + $options; |
---|
| 16 | |
---|
| 17 | $form['results_lifespan'] = array( |
---|
| 18 | '#type' => 'select', |
---|
| 19 | '#title' => t('Query results'), |
---|
| 20 | '#description' => t('The length of time raw query results should be cached.'), |
---|
| 21 | '#options' => $options, |
---|
| 22 | '#default_value' => $this->options['results_lifespan'], |
---|
| 23 | ); |
---|
| 24 | $form['output_lifespan'] = array( |
---|
| 25 | '#type' => 'select', |
---|
| 26 | '#title' => t('Rendered output'), |
---|
| 27 | '#description' => t('The length of time rendered HTML output should be cached.'), |
---|
| 28 | '#options' => $options, |
---|
| 29 | '#default_value' => $this->options['output_lifespan'], |
---|
| 30 | ); |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | function summary_title() { |
---|
| 34 | return format_interval($this->options['results_lifespan'], 1) . '/' . format_interval($this->options['output_lifespan'], 1); |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | function cache_expire($type) { |
---|
| 38 | if ($lifespan = $this->options[$type . '_lifespan']) { |
---|
| 39 | $cutoff = time() - $lifespan; |
---|
| 40 | return $cutoff; |
---|
| 41 | } |
---|
| 42 | else { |
---|
| 43 | return FALSE; |
---|
| 44 | } |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | function cache_set_expire($type) { |
---|
| 48 | if ($lifespan = $this->options[$type . '_lifespan']) { |
---|
| 49 | return time() + $lifespan; |
---|
| 50 | } |
---|
| 51 | else { |
---|
| 52 | return CACHE_PERMANENT; |
---|
| 53 | } |
---|
| 54 | } |
---|
| 55 | } |
---|