PASSWORD RESET

Your destination for complete Tech news

How to clear cache in Laravel?

371 0
< 1 min read

In Laravel, there are several ways to clear the cache:

  1. Artisan command php artisan cache:clear: This command will clear the application cache.
  2. Artisan command php artisan route:clear: This command will clear the route cache.
  3. Artisan command php artisan view:clear: This command will clear the compiled view files.
  4. Artisan command php artisan config:clear: This command will clear the configuration cache.
  5. Artisan command php artisan optimize: This command will clear all of the above caches and also optimize the framework for better performance.

You can also use the Artisan::call method to execute these commands programmatically:

Artisan::call('cache:clear');
Artisan::call('route:clear');
Artisan::call('view:clear');
Artisan::call('config:clear');
Artisan::call('optimize');

It’s also worth noting that some cache drivers, such as the Redis and Memcached drivers, provide their own cache clearing methods. You can use these methods to clear the cache for a specific key or for the entire cache.

For example, to clear the entire Redis cache:

$redis = app()->make('redis');
$redis->flushall();

Or to clear a specific key in the Memcached cache:

$memcached = app()->make('memcached');
$memcached->delete('key');

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.