Index: dmemcache.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/memcache/dmemcache.inc,v retrieving revision 1.1.2.7 diff -u -p -r1.1.2.7 dmemcache.inc --- dmemcache.inc 31 Jul 2007 11:29:41 -0000 1.1.2.7 +++ dmemcache.inc 15 Aug 2008 14:17:16 -0000 @@ -62,7 +62,18 @@ function dmemcache_get($key, $bin = 'cac $full_key = dmemcache_key($key, $bin); $result = $mc->get($full_key); if ($result) { - $_memcache_statistics['hit'][] = $key; + $object_expire_time = $result->expire > 2592000 ? $result->expire :$result->expire + $result->created; + $future_expire = time() + 30; + // If the object is expiring before the window set aside for regeneration + // we try to set a semaphore. If that also succeeds,then we make the + // object live just a little bit longer than the semaphore so that it + // can't expire while the semaphore is set. + if ($result->expire && $object_expire_time <= $future_expire && $mc->add($full_key .'_semaphore', '', FALSE, $future_expire - 1) && $mc->set($full_key, $result, MEMCACHE_COMPRESSED, $future_expire)) { + $result = FALSE; + } + else { + $_memcache_statistics['hit'][] = $key; + } } return $result; }