How To Clear Complete Application Caches in Laravel 10

Reading Time: 6 minutes
450 Views

We will look at the topic of How To Clear Complete Application Caches in Laravel 10 Tutorial in this article. As a Laravel developer, you understand the importance of caching in optimising the performance of your apps. However, there are times when clearing the entire cache is necessary to ensure accurate data and a pleasant user experience.

This tutorial will walk you through the process of removing the entire application caches in Laravel 10. Knowing how to clear the entire cache is critical for keeping the integrity of your application, whether you’re making changes to your codebase, upgrading configurations, or encountering caching issues.

Application caching, sometimes known as “app cache” is a web browser technology that allows static files (such as HTML, CSS, JavaScript, pictures, and other assets) to be stored locally on a user’s device.

Read More: How To Create and Download Zip File in Laravel 10 Tutorial

When we do application development in Laravel, as a developer you may have observed that site saves cache of route, view and routes. Due to this sometime changes doesn’t reflect to pages, we get the old data on the output screen.

To overcome this issue we are going to see the concept of Clear Cache Methods of Laravel.

The commands we will see not actually dependent on laravel version. It runs to all application of any version. These are global artisan commands. It provides the list of artisan command which helps to remove complete caches.

Let’s get started.

Laravel Installation

Open terminal and run this command to create a laravel project.

composer create-project laravel/laravel myblog

It will create a project folder with name myblog inside your local system.

To start the development server of laravel –

php artisan serve

URL: http://127.0.0.1:8000

Assuming laravel already installed inside your system.

Laravel Artisan Command Panel

When we open laravel project into terminal and type the command

$ php artisan

Read More: How To Query To Get Single Row Data in Laravel 10 Tutorial

You will see these commands.

This is complete commands list of laravel artisan. Inside this list you see the caches command to clear routes, views, optimized files, etc.

Cache Related Commands

Here,

We have listed all the artisan commands which will perform to clear caches of routes, views, etc.

Clear Application Compiled Classes

Remove the compiled class files

$ php artisan clear-compiled

Clear Application Cache

Flush the application cache

$ php artisan cache:clear

Clear Route Cache

Remove the route cache file

$ php artisan route:clear

Read More: Form Validation with Ajax Request in Laravel 10 Tutorial

Clear View Cache

Clear all compiled view files

$ php artisan view:clear

Clear Config Cache

Remove the configuration cache file

$ php artisan config:clear

Clear Application Scheduler Cache

Delete the cached mutex files created by scheduler

$ php artisan schedule:clear-cache

Clear All Queue Jobs

Delete all of the jobs from the specified queue

$ php artisan queue:clear

Remove All Event Cached Files

Clear all cached events and listeners

$ php artisan event:clear

Remove All Cached Bootstrap Files (Master Command)

Remove the cached bootstrap files. This command will do all caches clear of your application.

$ php artisan optimize:clear

Output

Cached events cleared successfully.
Compiled views cleared successfully.
Application cache cleared successfully.
Route cache cleared successfully.
Configuration cache cleared successfully.
Compiled services and packages files removed successfully.
Caches cleared successfully.

Run Clear Cache Command by Code

Inside this we will add a route in web.php of /routes folder.

Read More: How To Get File Size From File Path in Laravel 10 Tutorial

That route when we call, then it clears the cache of the application.

//...

use Illuminate\Support\Facades\Artisan;

Route::get('clear-all-cache', function() {
  
    Artisan::call('cache:clear');
  
    dd("Successfully, you have cleared all cache of application.");
});


//...

Behind the scene, it is going to execute the command as

$ php artisan cache:clear

Same we can do for route [ Artisan::call(‘route:clear’); ], views [ Artisan::call(‘view:clear’); ] & config [ Artisan::call(‘config:clear’); ]

Application Testing

Run this command into project terminal to start development server,

php artisan serve

URL: http://localhost:8000/clear-all-cache

We hope this article helped you to learn about How To Clear Complete Application Caches in Laravel 10 Tutorial in a very detailed way.

Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.

Sanjay KumarHello friends, I am Sanjay Kumar a Web Developer by profession. Additionally I'm also a Blogger, Youtuber by Passion. I founded Online Web Tutor and Skillshike platforms. By using these platforms I am sharing the valuable knowledge of Programming, Tips and Tricks, Programming Standards and more what I have with you all. Read more