美文网首页
laravel 缓存

laravel 缓存

作者: 爱折腾的傻小子 | 来源:发表于2019-01-18 11:06 被阅读21次
  • 配置文件缓存
php artisan config:cache 命令缓存./config目录下的所有配置文件到./bootstrap/cache/config.php里面
# 这里如果存在 ./config目录配置文件存在闭包函数 缓存不能被执行
  • 看一下缓存源码
    public function handle()
    {
        // 执行清除缓存命令 就是删除config.php文件
        $this->call('config:clear');
        // 获取./config 配置文件信息 返回数组的形式
        $config = $this->getFreshConfiguration();
        // 获取需要缓存的路径./bootstrap/cache/config.php
        $configPath = $this->laravel->getCachedConfigPath();
        // 数据写入 var_export($config, true) 返回合法的php代码 参考该php函数
        $this->files->put(
            $configPath, '<?php return '.var_export($config, true).';'.PHP_EOL
        );

        try {
            require $configPath;
        } catch (Throwable $e) {
            $this->files->delete($configPath);

            throw new LogicException('Your configuration files are not serializable.', 0, $e);
        }

        $this->info('Configuration cached successfully!');
    }

相关文章

网友评论

      本文标题:laravel 缓存

      本文链接:https://www.haomeiwen.com/subject/pxngdqtx.html