diff --git a/includes/cache.inc b/includes/cache.inc
index 521f36f99feffbaa225a88e95f0666409b3744d4..9fe7602c010b55d1c0dd8e1b69049aa96cc7778c 100644
--- a/includes/cache.inc
+++ b/includes/cache.inc
@@ -17,9 +17,10 @@ function cache_get($cid, $table = 'cache') {
   // Garbage collection necessary when enforcing a minimum cache lifetime
   $cache_flush = variable_get('cache_flush', 0);
   if ($cache_flush && ($cache_flush + variable_get('cache_lifetime', 0) <= time())) {
+    // Reset the variable immediately to prevent a meltdown in heavy load situations.
+    variable_set('cache_flush', 0);
     // Time to flush old cache data
     db_query("DELETE FROM {". $table ."} WHERE expire != %d AND expire <= %d", CACHE_PERMANENT, $cache_flush);
-    variable_set('cache_flush', 0);
   }
 
   $cache = db_fetch_object(db_query("SELECT data, created, headers, expire, serialized FROM {". $table ."} WHERE cid = '%s'", $cid));