diff --git a/memcache.inc b/memcache.inc
index af916b3..78296d1 100644
--- a/memcache.inc
+++ b/memcache.inc
@@ -154,7 +154,7 @@ function cache_get($cid, $table = 'cache') {
  *   The cache ID of the data to store.
  * @param $data
  *   The data to store in the cache. Complex data types will be automatically
- *   serialized before insertion. Strings will be stored as plain text and 
+ *   serialized before insertion. Strings will be stored as plain text and
  *   not serialized.
  * @param $table
  *   The table $table to store the data in. Valid core values are 'cache_filter',
@@ -370,7 +370,13 @@ function memcache_wildcards($cid, $table, $flush = FALSE) {
     // fraction of the wildcard invalidation variable, per cid length.  Defaults
     // to 28 / 4, or one week.
     $length = strlen($cid);
-    $key_length = isset($wildcard_flushes[$table]) ? strlen(reset(array_keys($wildcard_flushes[$table]))) : $length;
+    if (isset($wildcard_flushes[$table])) {
+      $wildcard_flushes_keys = array_keys($wildcard_flushes[$table]);
+      $key_length = strlen(reset($wildcard_flushes_keys));
+    }
+    else {
+      $key_length = $length;
+    }
     $key = substr($cid, 0, $key_length);
     if (!isset($wildcard_flushes[$table][$key][$length]) || ($_SERVER['REQUEST_TIME'] - $wildcard_flushes[$table][$key][$length] > $wildcard_invalidate / 4)) {
 
