Jamm\Memory\APCObject::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] = apc_fetch($this->prefix . $arr_key, $success);
                if (!$success) {
                    unset($data[$arr_key]);
                    continue;
                }
                if ($return_ttl) {
                    $ttl_left[$arr_key] = $this->getKeyTTL($arr_key);
                }
            }
        } else {
            $data = apc_fetch($this->prefix . $key, $success);
            if (!$success) {
                if (apc_exists($this->prefix . $key)) {
                    $this->ReportError('apc can not fetch key ' . $key, __LINE__);
                }
                return false;
            }
            if ($ttl_left !== -1) {
                $ttl_left = $this->getKeyTTL($key);
                if ($ttl_left < 0) {
                    $data = false;
                }
                //key expired
            }
        }
        return $data;
    }