src/Leevel/Cache/File.php
public function get(string $name, $defaults = false, array $option = [])
    {
        $option = $this->normalizeOptions($option);
        $cachePath = $this->getCachePath($name);

        // 清理文件状态缓存 http://php.net/manual/zh/function.clearstatcache.php
        clearstatcache();

        if (!is_file($cachePath)) {
            return false;
        }

        if (!is_readable($cachePath)) {
            throw new InvalidArgumentException('Cache path is not readable.');
        }

        $fp = fopen($cachePath, 'r');
        flock($fp, LOCK_SH);

        // 头部的 41 个字节存储了安全代码
        $len = filesize($cachePath);
        fread($fp, static::HEADER_LENGTH);
        $len -= static::HEADER_LENGTH;

        do {
            // 检查缓存是否已经过期
            if ($this->isExpired($name, $option)) {
                $data = false;

                break;
            }

            if ($len > 0) {
                $data = fread($fp, $len);
            } else {
                $data = false;
            }
        } while (false);

        flock($fp, LOCK_UN);
        fclose($fp);

        if (false === $data) {
            return false;
        }

        // 解码
        if ($option['serialize']) {
            $data = unserialize($data);
        }

        return $data;
    }
public function get(string $name, $defaults = false, array $option = [])
    {
        $option = $this->normalizeOptions($option);
        $cachePath = $this->getCachePath($name);

        // 清理文件状态缓存 http://php.net/manual/zh/function.clearstatcache.php
        clearstatcache();

        if (!is_file($cachePath)) {
            return false;
        }

        if (!is_readable($cachePath)) {
            throw new InvalidArgumentException('Cache path is not readable.');
        }

        $fp = fopen($cachePath, 'r');
        flock($fp, LOCK_SH);

        // 头部的 41 个字节存储了安全代码
        $len = filesize($cachePath);
        fread($fp, static::HEADER_LENGTH);
        $len -= static::HEADER_LENGTH;

        do {
            // 检查缓存是否已经过期
            if ($this->isExpired($name, $option)) {
                $data = false;

                break;
            }

            if ($len > 0) {
                $data = fread($fp, $len);
            } else {
                $data = false;
            }
        } while (false);

        flock($fp, LOCK_UN);
        fclose($fp);

        if (false === $data) {
            return false;
        }

        // 解码
        if ($option['serialize']) {
            $data = unserialize($data);
        }

        return $data;
    }
获取缓存.

@param string $name
@param mixed  $defaults
@param array  $option

@return mixed