Syamsoul Azrien
Syamsoul Azrien

Reputation: 2752

Laravel - Is the cache:clear command will clear config cache also?

I use Laravel 5.8, and as we know, there are 3 type of cache in Laravel

.

So, in my Laravel app, I use Cache::remember('mycachetoday', $seconds, function(){})...

In order to clear the mycachetoday, i must run php artisan cache:clear, right?

But I wonder if I run php artisan cache:clear, will the config, route, and view cache be cleared also?

Thanks

Upvotes: 1

Views: 8516

Answers (2)

TsaiKoga
TsaiKoga

Reputation: 13394

You can try

php artisan config:cache

The config cache file will be store in bootstrap/cache directory.

When you run

php artisan cache:clear

It will only clear the datas that you store by Cache. The config cache file still in bootstrap/cache.

After you run php artisan config:clear, the file will be deleted from bootstrap/cache.

Check the ClearCommand source code, there is no code that delete any config/route/view cache file in bootstrap/cache, and only clear the application 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!');
    }

Check the ConfigClearCommand source code, it will delete the config cache file.

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

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

Upvotes: 5

helderneves91
helderneves91

Reputation: 975

To clear everything, you can do php artisan optimize:clear. This will result in:

Compiled views cleared!
Application cache cleared!
Route cache cleared!
Configuration cache cleared!
Compiled services and packages files removed!
Caches cleared successfully!

Regards!

Upvotes: 5

Related Questions