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

0 votes

I am using Redis to cache queries/routes in Laravel 5.2.

I have 3 environments running on the same web server i.e "production", "staging", and "development."

For each environment I set a different cache prefix value to allow me to link the cache to different environment.

In the config/cache.php file I changed the line

'prefix' => 'laravel',

To

'prefix' => ENV('CACHE_PREFIX', 'laravel'),

Then in my .env file, I added the prefix for each environment like this

For Dev

CACHE_PREFIX="LaravelDev"

For Staging

CACHE_PREFIX="LaravelStaging"

For Production

CACHE_PREFIX="LaravelProduction"

I know I can clear the cache from the command line like this

php artisan cache:clear

But the code above will clear the cache for all of my environments.

I only want to clear the cache for "LaravelDev" only and leave alone "LaravelStaging" and "LaravelProduction"

How can I clear the cache for a specific environment?

Oct 28 in Laravel by kartik
• 35,500 points
37 views

1 answer to this question.

0 votes

Hello @kartik,

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.

Hope it helps!!

answered Oct 28 by Niroj
• 76,940 points

Related Questions In Laravel

0 votes
1 answer

How can we use the custom table in Laravel?

Hey, We can easily use custom table in ...READ MORE

answered Mar 20 in Laravel by Niroj
• 76,940 points
182 views
0 votes
1 answer

How can someone change the default database type in Laravel?

Laravel is configured to use MySQL by ...READ MORE

answered Mar 20 in Laravel by Niroj
• 76,940 points
746 views
0 votes
1 answer

How can we create a record in Laravel using eloquent?

We need to create a new model ...READ MORE

answered Mar 20 in Laravel by Niroj
• 76,940 points
137 views
0 votes
1 answer

How can we check the logged-in user info in Laravel?

Hey @kartik, yes we can keep track of ...READ MORE

answered Mar 20 in Laravel by Niroj
• 76,940 points
120 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18 in Laravel by Niroj
• 76,940 points
3,470 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18 in Laravel by Niroj
• 76,940 points
412 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23 in Laravel by Niroj
• 76,940 points
286 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23 in Laravel by Niroj
• 76,940 points
4,167 views
0 votes
1 answer

How can I echo the version of the current Laravel version in php using the view?

Hello @kartik, This is the way how to ...READ MORE

answered Aug 10 in Laravel by Niroj
• 76,940 points
124 views
0 votes
1 answer

How Can I Remove “public/index.php” in the URL Generated Laravel?

Hello @kartik, If it isn't already there, create ...READ MORE

answered Aug 10 in Laravel by Niroj
• 76,940 points
1,198 views