diff --git includes/common.inc includes/common.inc
index 63510d6..e8cec51 100644
--- includes/common.inc
+++ includes/common.inc
@@ -5183,7 +5183,7 @@ function drupal_render_cache_get($elements) {
   }
   $bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'cache';
 
-  if (!empty($cid) && $cache = cache_get($cid, $bin)) {
+  if ($cache = cache_get($cid, $bin)) {
     // Add additional libraries, JavaScript, CSS and other data attached
     // to this element.
     if (isset($cache->data['#attached'])) {
@@ -5192,7 +5192,15 @@ function drupal_render_cache_get($elements) {
     // Return the rendered output.
     return $cache->data['#markup'];
   }
-  return FALSE;
+  else {
+    // Cache miss. Avoid a stampede.
+    if (!lock_acquire($cid, 1)) {
+      // Some other request is building cache. Wait, then re-run this function.
+      sleep(1);
+      return drupal_render_cache_get($elements);
+    }
+    return FALSE;
+  }
 }
 
 /**
@@ -5228,6 +5236,7 @@ function drupal_render_cache_set(&$markup, $elements) {
   $bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'cache';
   $expire = isset($elements['#cache']['expire']) ? $elements['#cache']['expire'] : CACHE_PERMANENT;
   cache_set($cid, $data, $bin, $expire);
+  lock_release($cid);
 }
 
 /**
