Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

zoidq's avatar
Level 7

Redis cache not clearing with Artisan?

Hey guys,

I've had a quick search on the forum but can't find an answer, hoping someone can help.

On my local dev machine, I frequently run: php artisan migrate:fresh --seed

Since I'm caching things with redis via "Cache::" I need to flush the cache each time.

It would be ideal if I could figure how to do this automatically on each migration, perhaps I could add Cache::flush(); somewhere?

Problem:

When I run php artisan cache:clear, the cached data is not actually flushed. I confirm this using the redis-cli client and of course the cached data is still being shown in my app.

Setup: In config/cache.php I have the following: 'default' => env('CACHE_DRIVER', 'redis'),

Data is being stored with Cache::set('somekey', $data) and retrieved withCache::get('somekey')

Is there anything else I should be aware of?

Thanks!

0 likes
3 replies
max_well's avatar
max_well
Best Answer
Level 1

Maybe it's not using redis, have you overridden CACHE_DRIVER in your .env?

Or did you switch around cache drivers and maybe have you local config cached (php artisan config:clear) and thus it picks the wrong cache driver?

Ved21212's avatar
php artisan cache:clear;
php artisan config:clear
php artisan config:cache

Or maybe you could do something like

Route::get('clear_cache', function() {
    $clearCache = Artisan::call('cache:clear');
});

Hope this helps!! :) @zoidq

zoidq's avatar
Level 7

Thanks for both of your help!

The initial problem with the cache not being cleared was that there was indeed an override in .my env setting CACHE_DRIVER=file -- I don't remember putting it there but must have at some point I suppose!

Please or to participate in this conversation.