--- /Users/bend/Downloads/varnish/varnish.module	2010-07-19 20:10:37.000000000 +0100
+++ sites/all/modules/contributed/varnish/varnish.module	2011-01-10 11:16:14.000000000 +0000
@@ -143,21 +143,39 @@ function varnish_form_alter(&$form, $for
  * This borrows logic from cache_clear_all() to respect cache_lifetime.
  */
 function varnish_flush_caches() {
-  if (variable_get('varnish_flush_cron', 0)) {
-    if (variable_get('cache_lifetime', 0)) {
-      $cache_flush = variable_get('cache_flush_varnish', 0);
-      if ($cache_flush == 0) {
-        // This is the first request to clear the cache, start a timer.
-        variable_set('cache_flush_varnish', time());
-      }
-      else if (time() > ($cache_flush + variable_get('cache_lifetime', 0))) {
-        varnish_purge_all_pages();
-      }
+
+  //If this hook is called by CRON and the Varnish CRON flush is disabled, do not run
+  if (!variable_get('varnish_flush_cron', FALSE) && varnish_test_cron_called()){
+    return; 
+  }
+  
+  if (variable_get('cache_lifetime', 0)) {
+    $cache_flush = variable_get('cache_flush_varnish', 0);
+    if ($cache_flush == 0) {
+      // This is the first request to clear the cache, start a timer.
+      variable_set('cache_flush_varnish', time());
     }
-    else {
+    else if (time() > ($cache_flush + variable_get('cache_lifetime', 0))) {
       varnish_purge_all_pages();
     }
   }
+  else {
+    varnish_purge_all_pages();
+  }
+}
+
+
+/**
+ * Test if the process was called by CRON
+ */
+function varnish_test_cron_called() {
+  foreach (debug_backtrace(FALSE) as $level) {
+    if ($level['function'] == 'drupal_cron_run') {
+      return TRUE;
+    }
+  }
+
+  return FALSE;
 }
 
 /**
