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_definition() { |
---|
8 | $options = parent::option_definition(); |
---|
9 | $options['results_lifespan'] = array('default' => 3600); |
---|
10 | $options['output_lifespan'] = array('default' => 3600); |
---|
11 | |
---|
12 | return $options; |
---|
13 | } |
---|
14 | |
---|
15 | function options_form(&$form, &$form_state) { |
---|
16 | $options = array(60, 300, 1800, 3600, 21600, 518400); |
---|
17 | $options = drupal_map_assoc($options, 'format_interval'); |
---|
18 | $options = array(-1 => t('Never cache')) + $options; |
---|
19 | |
---|
20 | $form['results_lifespan'] = array( |
---|
21 | '#type' => 'select', |
---|
22 | '#title' => t('Query results'), |
---|
23 | '#description' => t('The length of time raw query results should be cached.'), |
---|
24 | '#options' => $options, |
---|
25 | '#default_value' => $this->options['results_lifespan'], |
---|
26 | ); |
---|
27 | $form['output_lifespan'] = array( |
---|
28 | '#type' => 'select', |
---|
29 | '#title' => t('Rendered output'), |
---|
30 | '#description' => t('The length of time rendered HTML output should be cached.'), |
---|
31 | '#options' => $options, |
---|
32 | '#default_value' => $this->options['output_lifespan'], |
---|
33 | ); |
---|
34 | } |
---|
35 | |
---|
36 | function summary_title() { |
---|
37 | return format_interval($this->options['results_lifespan'], 1) . '/' . format_interval($this->options['output_lifespan'], 1); |
---|
38 | } |
---|
39 | |
---|
40 | function cache_expire($type) { |
---|
41 | if ($lifespan = $this->options[$type . '_lifespan']) { |
---|
42 | $cutoff = time() - $lifespan; |
---|
43 | return $cutoff; |
---|
44 | } |
---|
45 | else { |
---|
46 | return FALSE; |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | function cache_set_expire($type) { |
---|
51 | if ($lifespan = $this->options[$type . '_lifespan']) { |
---|
52 | return time() + $lifespan; |
---|
53 | } |
---|
54 | else { |
---|
55 | return CACHE_PERMANENT; |
---|
56 | } |
---|
57 | } |
---|
58 | } |
---|