I'm using PHP's PECL/Memcached for the first time and I can't figure out when or how I should be updating changed items in Memcached.
I've tried using both Memcached::add
and Memcached::set
and neither yields the results I expect.
Memcached::set
replaces the value automatically
$memcached->set('key', 'value', time() + 300);
$memcached->set('key', 'value2', time() + 300);
var_dump($memcached->get('key')); // Outputs "value2"
and Memcached::add
won't replace the value if it's already set in Memcached
$memcached->add('key', 'value');
$memcached->add('key', 'value2';
var_dump($memcached->get('key')); // Outputs "value"
So what's the typical practice for updating values in Memcached?