diff --git a/memcache.inc b/memcache.inc
index af916b3..66c0eac 100644
--- a/memcache.inc
+++ b/memcache.inc
@@ -432,11 +432,13 @@ function memcache_variable_set($name, $value) {
   }
   // If the variables are cached, get a fresh copy, update with the new value
   // and set it again.
-  if ($cached = cache_get('variables', 'cache')) {
+  if ($cached = cache_get('variables', 'cache') && !empty($cached->data)) {
     $variables = $cached->data;
     $variables[$name] = $value;
     cache_set('variables', $variables);
   }
-  // If the variables aren't cached, there's no need to do anything.
+  // If the variables aren't cached, there's no need to do anything, but to
+  // ensure no opportunity for race conditions, clear the cache just in case.
   $conf[$name] = $value;
+  cache_clear_all('variables', 'cache');
 }
