=== modified file 'sites/all/modules/contrib/memcache/memcache.inc'
--- sites/all/modules/contrib/memcache/memcache.inc 2010-09-01 19:38:30 +0000
+++ sites/all/modules/contrib/memcache/memcache.inc 2010-09-02 11:08:05 +0000
@@ -200,6 +200,26 @@ class MemCacheDrupal implements DrupalCa
    */
   private function wildcards($cid, $flush = FALSE) {
     static $wildcards = array();
+
+    // Some bins will not have a wildcard flush, in those cases we can always
+    // return 0 without doing a separate lookup.
+    $wildcard_flushes = variable_get('memcache_wildcard_flushes', array());
+    if ($flush) {
+      debug('hello');
+      debug($this->bin);
+      debug($cid);
+      // Store a timestamp for wildcard flushes at granularity of an hour
+      // storing every flush could lead to too many variable_set().
+      if (empty($wildcard_flushes[$this->bin]) || $wildcard_flushes[$this->bin] <= time() - 600) {
+        $wildcard_flushes[$this->bin] = time();
+        variable_set('memcache_wildcard_flushed', $wildcard_flushes);
+      }
+    }
+    // If there have been no wildcard flushes of this bin, or the last wildcard
+    // flush was more than a month ago, return 0 here to avoid looking this up.
+    elseif (empty($wildcard_flushes[$this->bin]) || $wildcard_flushes[$this->bin] <= time() - variable_get('memcache_wildcard_invalidate', 86400 * 28)) {
+      return array();
+    }
     if (!isset($wildcard[$this->bin]) || !isset($wildcards[$this->bin][$cid])) {
       $multihash = $this->multihash_cid($cid);
       $wildcards[$this->bin][$cid] = dmemcache_get_multi($multihash, $this->bin);


