Jamm\Memory\MemcacheObject::lock_key PHP Method

lock_key() public method

Get exclusive mutex for key. Key will be still accessible to read and write, but another process can exclude dog-pile effect, if before updating the key he will try to get this mutex.
public lock_key ( mixed $key, mixed &$auto_unlocker_variable ) : boolean
$key mixed
$auto_unlocker_variable mixed - pass empty, just declared variable
return boolean
    public function lock_key($key, &$auto_unlocker_variable)
    {
        $r = $this->memcache->add($this->lock_key_prefix . $key, 1, null, $this->key_lock_time);
        if (!$r) {
            return false;
        }
        $auto_unlocker_variable = new KeyAutoUnlocker(array($this, 'unlock_key'));
        $auto_unlocker_variable->setKey($key);
        return true;
    }