Laravel - 缓存:清除命令也会清除配置缓存吗?

Sya*_*ien 1 caching laravel

我使用 Laravel 5.8,据我们所知,Laravel 中有 3 种类型的缓存

  • 配置缓存 ( php artisan config:cache)
  • 路由缓存 ( php artisan route:cache)
  • 查看缓存 ( php artisan view:cache)

所以,在我的 Laravel 应用程序中,我使用Cache::remember('mycachetoday', $seconds, function(){})...

为了清除mycachetoday,我必须跑php artisan cache:clear,对吗?

但我想知道如果我运行php artisan cache:clear,配置、路由和视图缓存也会被清除吗?

谢谢

Tsa*_*oga 5

你可以试试

php artisan config:cache
Run Code Online (Sandbox Code Playgroud)

配置缓存文件将存储在bootstrap/cache目录中。

当你跑步时

php artisan cache:clear
Run Code Online (Sandbox Code Playgroud)

它只会清除您存储的数据Cache。配置缓存文件仍在bootstrap/cache.

运行后php artisan config:clear,该文件将从 中删除bootstrap/cache

查看ClearCommand源码,没有删除任何config/route/view缓存文件的代码bootstrap/cache,仅清除应用程序缓存。

/**
     * Execute the console command.
     *
     * @return void
     */
    public function handle()
    {
        $this->laravel['events']->dispatch(
            'cache:clearing', [$this->argument('store'), $this->tags()]
        );

        $successful = $this->cache()->flush();

        $this->flushFacades();

        if (! $successful) {
            return $this->error('Failed to clear cache. Make sure you have the appropriate permissions.');
        }

        $this->laravel['events']->dispatch(
            'cache:cleared', [$this->argument('store'), $this->tags()]
        );

        $this->info('Application cache cleared!');
    }
Run Code Online (Sandbox Code Playgroud)

检查ConfigClearCommand源代码,它会删除配置缓存文件。

/**
     * Execute the console command.
     *
     * @return void
     */
    public function handle()
    {
        $this->files->delete($this->laravel->getCachedConfigPath());

        $this->info('Configuration cache cleared!');
    }
Run Code Online (Sandbox Code Playgroud)


hel*_*s91 5

要清除一切,你可以这样做php artisan optimize:clear。这将导致:

Compiled views cleared!
Application cache cleared!
Route cache cleared!
Configuration cache cleared!
Compiled services and packages files removed!
Caches cleared successfully!
Run Code Online (Sandbox Code Playgroud)

问候!