Home > PHP Framework > Laravel > body text

laravel delete cache

WBOY
Release: 2023-05-20 16:40:09
Original
5507 people have browsed it

Laravel is an excellent PHP framework that uses many advanced technologies, such as Composer, Blade engine, Eloquent ORM, etc. However, when using Laravel, we sometimes encounter cache problems. For example, a file is modified but the website is still not updated. In this case, the cache needs to be cleared. This article will introduce how to delete cache in Laravel.

1. Clear the configuration cache

Laravel’s configuration file will be cached, which can improve program performance. When we modify the configuration file in the config directory, we need to clear the cache for the new configuration file to take effect. The method to clear the configuration cache is as follows:

Open a terminal window in the root directory of the Laravel project, and then run the following command:

php artisan config:cache
Copy after login

After executing this command, Laravel will generate the configuration cache file in bootstrap /cache directory. If you want to clear the cache file, you can use the following command:

php artisan config:clear
Copy after login

After executing this command, Laravel will delete the bootstrap/cache/config.php file.

2. Clear the routing cache

Laravel’s routing files will be cached, which can improve program performance. When we modify the routes/web.php or routes/api.php file, we need to clear the cache to make the new routing file take effect. The method to clear the route cache is as follows:

Open a terminal window in the root directory of the Laravel project, and then run the following command:

php artisan route:clear
Copy after login

After executing this command, Laravel will delete bootstrap/cache/routes. php file. If you want to regenerate the route cache file, you can use the following command:

php artisan route:cache
Copy after login

After executing this command, Laravel will generate the route cache file in the bootstrap/cache directory.

3. Clear the view cache

Laravel’s view files will also be cached, which can improve program performance. When we modify a view file, we need to clear the cache for the new view file to take effect. The method to clear the view cache is as follows:

Open a terminal window in the root directory of the Laravel project, and then run the following command:

php artisan view:clear
Copy after login

After executing this command, Laravel will delete the storage/framework/views directory Download all view cache files.

4. Clear the service cache

Laravel's service container will cache bound class instances, which can improve program performance. When we register a class in AppServiceProvider, we need to clear the cache for the new class to take effect. The method to clear the service cache is as follows:

Open a terminal window in the root directory of the Laravel project, and then run the following command:

php artisan clear-compiled
Copy after login

After executing this command, Laravel will delete the files in the bootstrap/cache directory compiled.php file.

5. Clear all caches

If you want to clear all Laravel caches at once, you can use the following command:

php artisan cache:clear
Copy after login

After executing this command, Laravel will delete storage/ All files in the framework/cache directory, and the config.php, routes.php, services.php and packages.php files in the bootstrap/cache directory.

Summary

Through the introduction of this article, we can clearly understand the method of deleting cache in Laravel. These methods can help us take effect in time after modifying the program and ensure the normal operation of the program. When using Laravel, caching is an important optimization method, but you must also pay attention to clearing the cache in time, otherwise it will cause unnecessary trouble.

The above is the detailed content of laravel delete cache. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!