I'm migrating from memcache to memcached and one of the differences I've noticed is that the compression flag seems to be set for all set()
calls, not on an individual basis like with memcache
.
Is this a per-connection setting, or can I toggle this on and off? If it's the latter, what would be the best way to go about setting the compression flag for each set()
call?
Currently I'm thinking of doing something like this:
<?php
if ($compress) $mc->setOption(Memcached::OPT_COMPRESSION,true);
$return = $mc->set($key,$object,$expiration);
if ($compress) $mc->setOption(Memcached::OPT_COMPRESSION,false);
Is this the right approach?
I'm also setting up $mc
like this, if it makes any difference:
<?php
$mc = new Memcached("cl");
$mc->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE,true);
$mc->setOption(Memcached::OPT_BINARY_PROTOCOL,true);
if (count($mc->getServerList()) === 0) {
$mc->addServers(array (
array ($GLOBALS["mc"]["host"],$GLOBALS["mc"]["port"]),
));
}
Thanks!