ChatGPT解决这个技术问题 Extra ChatGPT

Flush all cache in Laravel 4

Is there a way to flush all cache in Laravel 4? I'm using file for caching. I read on the docs that you can use Cache::forget('key') , but what if I need to delete all the cache?

An artisan command can also be useful, I think there's an issue on the repo, but not sure if it's implemented yet.

Thanks!


M
Maciej Swic

If you run php artisan list then you can find all the commands available for artisan, anyways, there is a command to clear the cache and it's

php artisan cache:clear

Also, you can use

foreach (Cache::getMemory() as $cacheKey => $cacheValue)
{

    Cache::forget($cacheKey);
}

Update:

Cache::flush();

as of the time I'm writing this you can use Cache::flush() regardless of driver you are using. See the Laravel API Cache for this.
php artisan cache:clear might not always work in case of FileStore cache as the user who is executing the artisan command might not have write permissions to the cache files/directories. Usually the cached files are created by the webserver user who is not necessarily the same you use to run artisan.
Thanks @anonymous, I'll remember your advice and I'm really glad that you mentioned you downvoted because often some folks down votes anonymously and makes me confused. :-)
a
afroald

Illuminate\Cache\FileStore has the function flush, so you can use:

Cache::flush();

A
Anshad Vattapoyil

Use,

use Doctrine\Common\Cache\CacheProvider as DoctrineCache;

DoctrineCache::flushAll();

to flush all cache.


It's available in vendor/doctrine/cache/lib/Doctrine/Common/Cache/CacheProvider.php

关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now