Jamm\Memory\MemcacheObject::read PHP Method

read() public method

Read data from memory storage
public read ( string | array $key, mixed &$ttl_left ) : mixed
$key string | array (string or array of string keys)
$ttl_left mixed = (ttl - time()) of key. Use to exclude dog-pile effect, with lock/unlock_key methods.
return mixed
    public function read($key, &$ttl_left = -1)
    {
        if (is_array($key)) {
            $data = array();
            $return_ttl = $ttl_left !== -1 ? true : false;
            $ttl_left = array();
            foreach ($key as $arr_key) {
                $arr_key = (string) $arr_key;
                $data[$arr_key] = $this->memcache->get($this->prefix . $arr_key);
                if ($data[$arr_key] === false || $data[$arr_key] === null) {
                    unset($data[$arr_key]);
                    continue;
                }
                if ($return_ttl) {
                    $ttl_left[$arr_key] = $this->getKeyTTL($arr_key);
                    if ($ttl_left < 0) {
                        unset($data[$arr_key]);
                        $this->del($arr_key);
                    }
                }
            }
        } else {
            $data = $this->memcache->get($this->prefix . $key);
            if ($data === false || $data === null) {
                if (strlen($key) > 250) {
                    $this->ReportError('Length of key should be <250', __LINE__);
                }
                return false;
            }
            if ($ttl_left !== -1) {
                $ttl_left = $this->getKeyTTL($key);
                if ($ttl_left < 0) {
                    $data = false;
                    $this->del($key);
                }
            }
        }
        return $data;
    }