From d697cca1ecbb932b6bfd20582aae154e4ea0fc50 Mon Sep 17 00:00:00 2001
From: Joseph McGuire <joseph.p.mcguire@googlemail.com>
Date: Tue, 8 Nov 2011 11:01:30 +0000
Subject: [PATCH] Added settings option to exclude cache_shorten from hook_flush_cache() so that the cache can be manually managed and not cleared by Drupal's clear_cache_all(). See [#1335166].

---
 shorten.admin.inc |    7 +++++++
 shorten.install   |    1 +
 shorten.module    |    8 +++++++-
 3 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/shorten.admin.inc b/shorten.admin.inc
index e67b3e2..51f8ee5 100644
--- a/shorten.admin.inc
+++ b/shorten.admin.inc
@@ -156,6 +156,13 @@ function shorten_admin($form, $form_state) {
     '#default_value' => variable_get('shorten_invisible_services', array()),
     '#options' => $services,
   );
+   $form['shorten_clear_cache_all'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Allow Drupal to clear cache'),
+    '#description' => t('By default Drupal will clear all caches after running database updates or clicking clear cache on the performance page.') . ' ' .
+      t('To manage when you clear the shorten cache manually uncheck this option.'),
+    '#default_value' => variable_get('shorten_clear_cache_all', TRUE),
+  );
   return system_settings_form($form);
 }
 
diff --git a/shorten.install b/shorten.install
index 9b01e80..b3c2628 100644
--- a/shorten.install
+++ b/shorten.install
@@ -47,4 +47,5 @@ function shorten_uninstall() {
   variable_del('shorten_service_backup');
   variable_del('shorten_invisible_services');
   variable_del('shorten_cache_fail_duration');
+  variable_del('shorten_clear_cache_all');
 }
diff --git a/shorten.module b/shorten.module
index 8ae1132..be98c8d 100644
--- a/shorten.module
+++ b/shorten.module
@@ -111,7 +111,13 @@ function shorten_permission() {
  * Implements hook_flush_caches().
  */
 function shorten_flush_caches() {
-  return array('cache_shorten');
+  $caches = array();
+  // Shorten cache has an option to be excluded from cache_clear_all() to stop
+  // the cache being cleared after database updates.
+  if (variable_get('shorten_clear_cache_all', TRUE)) {
+    $caches[] = 'cache_shorten';
+  }
+  return $caches;
 }
 
 /**
-- 
1.7.4.1

