Cml\Cache\File::get PHP Метод

get() публичный Метод

获取缓存
public get ( string $key ) : mixed
$key string 要获取的缓存key
Результат mixed
    public function get($key)
    {
        $fileName = $this->getFileName($key);
        if (!is_file($fileName)) {
            return false;
        }
        $fp = fopen($fileName, 'r+');
        if ($this->lock) {
            //自增自减  上锁
            if (flock($fp, LOCK_EX) === false) {
                return false;
            }
            $this->lock = $fp;
        }
        $data = fread($fp, filesize($fileName));
        if ($data === false) {
            fclose($fp);
            return false;
        } else {
            $this->lock || fclose($fp);
            //非自增自减操作时关闭文件
        }
        //缓存过期
        $fileTime = substr($data, 13, 10);
        $pos = strpos($data, ')');
        $cacheTime = substr($data, 24, $pos - 24);
        $data = substr($data, $pos + 1);
        if ($cacheTime == 0) {
            return unserialize($data);
        }
        if (Cml::$nowTime > intval($fileTime) + intval($cacheTime)) {
            unlink($fileName);
            $this->lock && fclose($fp);
            return false;
            //缓存过期
        }
        return unserialize($data);
    }