Attached is a patch to allow users to set a custom time length for a cache to expire (ie 3 minutes, 1.5 days, etc...). The patch adds a "custom" option to the time drop down select. When "custom" is chosen for either output or results cache's then a text field appears where someone can enter a number of seconds for the cache to last for.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tim.plunkett’s picture

Status: Needs review » Needs work
+++ b/plugins/views_plugin_cache_time.incundefined
@@ -17,6 +19,7 @@ class views_plugin_cache_time extends views_plugin_cache {
     $options = array(-1 => t('Never cache')) + $options;
+    $options += array('custom' => t('Custom'));

These lines could probably be combined.

+++ b/plugins/views_plugin_cache_time.incundefined
@@ -25,6 +28,18 @@ class views_plugin_cache_time extends views_plugin_cache {
+      '#description' => 'Length of time in seconds raw query results should be cached',

wrap in t()

+++ b/plugins/views_plugin_cache_time.incundefined
@@ -32,14 +47,40 @@ class views_plugin_cache_time extends views_plugin_cache {
+      '#description' => 'Length of time in seconds rendered HTML output should be cached',

wrap in t()

+++ b/plugins/views_plugin_cache_time.incundefined
@@ -32,14 +47,40 @@ class views_plugin_cache_time extends views_plugin_cache {
+    $custom_fields = array('output_lifespan','results_lifespan');

missing space after comma

+++ b/plugins/views_plugin_cache_time.incundefined
@@ -32,14 +47,40 @@ class views_plugin_cache_time extends views_plugin_cache {
+      if ($form_state['values']['cache_options'][$field] == 'custom' && !is_numeric($form_state['values']['cache_options'][$field . '_custom'])) {

would this need an isset() to prevent notices?

+++ b/plugins/views_plugin_cache_time.incundefined
@@ -32,14 +47,40 @@ class views_plugin_cache_time extends views_plugin_cache {
+    $custom_fields = array('output_lifespan','results_lifespan');

missing space after comma

bigjim’s picture

Status: Needs work » Needs review
FileSize
4.33 KB

All except the isset() re-rolled here. On the isset() question I believe it's not needed as event the "never cache" options returns a -1 for the first condition of the if() so there is always a value.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
4.41 KB

Rerolled for git credit for @jalama, and adding full stops to the end of a string. I don't think this needs tests, since its really a UI thing.

The validate works, it gets exported properly, and the UI works.

dawehner’s picture

Version: 7.x-3.x-dev » 6.x-3.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Thanks! Committed to 7.x-3.x

MustangGB’s picture

Issue summary: View changes
Status: Patch (to be ported) » Closed (won't fix)