commit fe4c59ddfcd4d4928416fe6eaa515d0b9159c28c
Author: Jim Taylor <jtaylor@rootyhollow.com>
Date:   Tue Mar 6 21:52:59 2012 -0500

    Custom cache

diff --git a/plugins/views_plugin_cache_time.inc b/plugins/views_plugin_cache_time.inc
index 5ca0551..9b98225 100644
--- a/plugins/views_plugin_cache_time.inc
+++ b/plugins/views_plugin_cache_time.inc
@@ -14,7 +14,9 @@ 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;
   }
@@ -23,7 +25,7 @@ class views_plugin_cache_time extends views_plugin_cache {
     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;
+    $options = array(-1 => t('Never cache')) + $options + array('custom' => t('Custom'));
 
     $form['results_lifespan'] = array(
       '#type' => 'select',
@@ -32,6 +34,18 @@ class views_plugin_cache_time extends views_plugin_cache {
       '#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'),
@@ -39,14 +53,40 @@ class views_plugin_cache_time extends views_plugin_cache {
       '#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() {
-    return format_interval($this->options['results_lifespan'], 1) . '/' . format_interval($this->options['output_lifespan'], 1);
+    $custom_fields = array('output_lifespan', 'results_lifespan');
+    foreach ($custom_fields as $field) {
+      ${$field} = $this->options[$field] == 'custom' ? $this->options[$field . '_custom'] : $this->options[$field];
+    }
+    return format_interval($results_lifespan, 1) . '/' . format_interval($output_lifespan, 1);
   }
 
   function cache_expire($type) {
-    if ($lifespan = $this->options[$type . '_lifespan']) {
+    $lifespan = $this->options[$type . '_lifespan'] == 'custom' ? $this->options[$type . '_lifespan_custom'] : $this->options[$type . '_lifespan'];
+    if ($lifespan) {
       $cutoff = REQUEST_TIME - $lifespan;
       return $cutoff;
     }
@@ -56,7 +96,8 @@ class views_plugin_cache_time extends views_plugin_cache {
   }
 
   function cache_set_expire($type) {
-    if ($lifespan = $this->options[$type . '_lifespan']) {
+    $lifespan = $this->options[$type . '_lifespan'] == 'custom' ? $this->options[$type . '_lifespan_custom'] : $this->options[$type . '_lifespan'];
+    if ($lifespan) {
       return time() + $lifespan;
     }
     else {
