【问题标题】:Laravel - Is the cache:clear command will clear config cache also?Laravel - cache:clear 命令是否也会清除配置缓存?
【发布时间】:2020-03-11 21:42:52
【问题描述】:

我使用 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,配置、路由和视图缓存也会被清除吗?

谢谢

【问题讨论】:

  • 不,它不会清除它们。

标签: laravel caching


【解决方案1】:

你可以试试

php artisan config:cache

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

当你运行时

php artisan cache:clear

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

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

查看ClearCommand source codebootstrap/cache中没有删除任何config/route/view缓存文件的代码,只清除应用缓存。

/**
     * 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!');
    }

检查ConfigClearCommand source code,它将删除配置缓存文件。

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

        $this->info('Configuration cache cleared!');
    }

【讨论】:

    【解决方案2】:

    要清除所有内容,您可以使用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!
    

    问候!

    【讨论】:

    • 虽然它与这个问题无关......但是......无论如何哇......很高兴知道这个......我只是知道这个......谢谢......我赞成你的回答
    • 感谢@SyamsoulAzrien,正如您所说,这不是特定于问题的,但此命令在开发和发布应用程序时非常有用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-09
    • 2021-08-11
    • 2015-09-27
    • 2018-01-15
    • 1970-01-01
    • 2016-11-10
    • 1970-01-01
    相关资源
    最近更新 更多