diff --git a/dmemcache.inc b/dmemcache.inc index 6a80be2c25ce0413f388e4e0500a3c902ec98ccc..61b08428b5e5b8bcbad46b5bc268adf18bc20d84 100644 --- a/dmemcache.inc +++ b/dmemcache.inc @@ -19,14 +19,17 @@ $_memcache_statistics = array('get' => array(), 'set' => array(), 'hit' => array /** * Place an item into memcache * - * @param $key The string with with you will retrieve this item later. + * @param $key The string with which you will retrieve this item later. * @param $value The item to be stored. - * @param $exp Parameter expire is expiration time in seconds. If it's 0, the item never expires - * (but memcached server doesn't guarantee this item to be stored all the time, it could be - * deleted from the cache to make place for other items). - * @param $bin The name of the Drupal subsystem that is making this call. Examples could be - * 'cache', 'alias', 'taxonomy term' etc. It is possible to map different $bin values to - * different memcache servers. + * @param $exp Parameter expire is expiration time in seconds. If it's 0, the + * item never expires (but memcached server doesn't guarantee this item to be + * stored all the time, it could be deleted from the cache to make place for + * other items). + * @param $bin The name of the Drupal subsystem that is making this call. + * Examples could be 'cache', 'alias', 'taxonomy term' etc. It is possible to + * map different $bin values to different memcache servers. + * @param $mc Optionally pass in the memcache object. Normally this value is + * determined automatically based on the bin the object is being stored to. * * @return bool */ @@ -37,19 +40,37 @@ function dmemcache_set($key, $value, $exp = 0, $bin = 'cache', $mc = NULL) { if ($mc || ($mc = dmemcache_object($bin))) { $full_key = dmemcache_key($key, $bin); error_log("setting: ". $full_key . gmdate('c') . "\n", 3, '/tmp/log'); - if (class_exists('Memcached') && !$mc->set($full_key, $value, $exp)) { - return FALSE; - } - else if (class_exists('Memcache') && !$mc->set($full_key, $value, MEMCACHE_COMPRESSED, $exp)) { - return FALSE; + if (class_exists('Memcached')) { + return $mc->set($full_key, $value, $exp); } else { - return TRUE; + return $mc->set($full_key, $value, MEMCACHE_COMPRESSED, $exp); } } return FALSE; } +/** + * Add an item into memcache + * + * @param $key The string with which you will retrieve this item later. + * @param $value The item to be stored. + * @param $exp Parameter expire is expiration time in seconds. If it's 0, the + * item never expires (but memcached server doesn't guarantee this item to be + * stored all the time, it could be deleted from the cache to make place for + * other items). + * @param $bin The name of the Drupal subsystem that is making this call. + * Examples could be 'cache', 'alias', 'taxonomy term' etc. It is possible + * to map different $bin values to different memcache servers. + * @param $mc Optionally pass in the memcache object. Normally this value is + * determined automatically based on the bin the object is being stored to. + * @param $flag If using the older memcache PECL extension as opposed to the + * newer memcached PECL extension, the MEMCACHE_COMPRESSED flag can be set + * to use zlib to store a compressed copy of the item. This flag option is + * completely ignored when using the newer memcached PECL extension. + * + * @return bool + */ function dmemcache_add($key, $value, $exp = 0, $bin = 'cache', $mc = NULL, $flag = FALSE) { global $_memcache_statistics; $_memcache_statistics['add'][] = $key; @@ -64,6 +85,7 @@ function dmemcache_add($key, $value, $exp = 0, $bin = 'cache', $mc = NULL, $flag return $mc->add($key, $value, $flag, $exp); } } + return FALSE; } /** diff --git a/memcache.inc b/memcache.inc index 07b8a9ddd8990993f380d8579ef11761e310b2b9..62c07e2f60cbff3490006761816ec59cd9f370d8 100644 --- a/memcache.inc +++ b/memcache.inc @@ -19,9 +19,12 @@ class MemCacheDrupal implements DrupalCacheInterface { $results = dmemcache_get_multi(&$cids, $this->bin, $this->memcache); foreach ($results as $cid => $result) { if (!$this->valid($cid, $result)) { + // This object has expired, so don't return it. unset($results[$cid]); } else { + // Remove items from the referenced $cids array that we are returning, + // per the comment in cache_get_multiple() in includes/cache.inc. unset($cids[$cid]); } }