How can I clear the cache in laravel using command line? How can I clear the cache in laravel using command line? laravel laravel

How can I clear the cache in laravel using command line?


Instead of using CACHE_PREFIX you can use different redis databases. For ex: production => 1, staging => 2, development => 3.Use this links if you want to be a little bit more familiar with it:

  1. What's the Point of Multiple Redis Databases?
  2. List All Redis Databases

So, in your .env file for each environment (production/stage/dev) you need to define different REDIS_CACHE_DB env value.

Link to the line uses this variable https://github.com/laravel/laravel/blob/2a2522d8824c0852e30a7e3e07d46a543eb4b33d/config/database.php#L142 .Examples of .env:

.env.production

REDIS_CACHE_DB=1

.env.stage

REDIS_CACHE_DB=2

.env.development

REDIS_CACHE_DB=3

Don't forget to clear config cache after changing env variables: https://laravel.com/docs/7.x/configuration#configuration-caching

Hope this helps!


What the cache:clear artisan command does calls flush function on current connector. As caching engines varies with functionality I don't think it's possible to expire keys selectively keeping cache API universal. Engines like Redis provides such functionality, but memcached for example don't.

If you're using Redis you can modify default connector to use 'SCAN / DEL' commands for flush() method. Still this is not going to be very effective.

If your application uses cache correctly flushing it should not cause any problems as the cache will rebuild itself. You should never expect some data being in the cache as it might expire anyway.