I’m using Memcached with PHP, the code is like this :
$m = new Memcache;
$m->connect('myserver', 11213);
$key = ... // calculate key
$value = $m->get($key);
if($value) return $value
// calculate $value
$m->set($key, $value, 3600);
#var_dump($m->get($key);
Now weird thing is like this :
if I uncomment the var_dump line, I can see the data retrieved and dumped. That’s right after it’s pushed into Memcached. However, this line
$value = $m->get($key);
just always return false.
I’m sure the $key is consistent.
What possibly can go wrong?
It may be confused about the third parameter. According to the documentation, it’s for a flag, to enable compression (use
MEMCACHE_COMPRESSED), and then the fourth is for a timeout (number of seconds, or a particular time in the future)Memcache::set(string $key, mixed $var [, int $flag [, int $expire ]])