--- Memcached.php 2009-02-05 16:37:09.000000000 -0800 +++ Memcached_Modified.php 2009-02-05 16:44:28.000000000 -0800 @@ -190,10 +190,8 @@ } else { $flag = 0; } - if ($this->test($id)) { - // because set and replace seems to have different behaviour - $result = $this->_memcache->replace($id, array($data, time(), $lifetime), $flag, $lifetime); - } else { + // set is required if the key already exists, but add is faster if it doesn't + if (!$result = $this->_memcache->add($id, array($data, time(), $lifetime), $flag, $lifetime)) { $result = $this->_memcache->set($id, array($data, time(), $lifetime), $flag, $lifetime); } if (count($tags) > 0) { @@ -437,13 +435,9 @@ if ($newLifetime <=0) { return false; } - if ($this->test($id)) { - // because set and replace seems to have different behaviour - $result = $this->_memcache->replace($id, array($data, time(), $newLifetime), $flag, $newLifetime); - } else { - $result = $this->_memcache->set($id, array($data, time(), $newLifetime), $flag, $newLifetime); - } - return true; + $result = $this->_memcache->set($id, array($data, time(), $lifetime), $flag, $lifetime); + + return $result; } return false; }