memcached not storing array of complex items with specific keys


February 2019


37 time


Somehow I can't store an array of complex items if I put user_ as prefix for the key

The php code

$this->skills = [
    'defensiv' => DefensivSkill::getAllUserSkills($this),
    'offensiv' => OffensivSkill::getAllUserSkills($this),
    'spezial'  => SpezialSkill::getAllUserSkills($this),
    'pve'      => PVESkill::getAllUserSkills($this)

//is not stored
$_MEMCACHED->set('user_'.$this->getUserId().'_skills', $this->skills);

//is stored
$_MEMCACHED->set($this->getUserId().'_skills', $this->skills);

I call getAllKeys() after this and check if its stored...

I thought about the key length, but thats not the problem. After checking the key is 30 chars long - but I already have keys which are 39 chars long.

$_MEMCACHED = new Memcached();
$_MEMCACHED->addServer('localhost', 11212);
$_MEMCACHED->setOption(Memcached::OPT_PREFIX_KEY, 'hogsmeade_');

This is my connector, the MemCached Server runs with 4GB total limit, and 256mb item limit. The classes of the object implements serializable. memcached is compiled with igbinary support

Memcached v1.5.12 php-memcached v3.0.3 lib_memcached 1.0.18

The serialized array $this->skills is ~4500chars long (var_dump())

This works - only fails if I start the key with user_

$_MEMCACHED->set('cache_user_'.$this->getUserId().'_skills', $this->skills);

I did also extend memcached to track if I delete it somewhere

class MyMemcached extends Memcached
public function delete($key, $time = 0)
    file_put_contents(ROOT.'/memcache.log', 'DELETE '.$key, FILE_APPEND);
    parent::delete($key, $time); // TODO: Change the autogenerated stub

public function deleteMulti(array $keys, $time = 0)
    file_put_contents(ROOT.'/memcache.log', 'DELETE '.json_encode($keys), FILE_APPEND);
    parent::deleteMulti($keys, $time); // TODO: Change the autogenerated stub

but I dont

For both set actions the SUCCESS code is returned after set

$_MEMCACHED->set('user_'.$this->getUserId().'_skills', $this->skills); 
// works if I call it in the same execution

0 answers