Laravel 5 Clear Views Cache

Laravel 5 Clear Views Cache

There is now a php artisan view:clear command for this task since Laravel 5.1

Laravel 5 – Clear Cache in Shared Hosting Server

You can call an Artisan command outside the CLI.

Route::get('/clear-cache', function() {
$exitCode = Artisan::call('cache:clear');
// return what you want
});

You can check the official doc here
http://laravel.com/docs/5.0/artisan#calling-commands-outside-of-cli


Update

There is no way to delete the view cache. Neither php artisan cache:cleardoes that.

If you really want to clear the view cache, I think you have to write your own artisan command and call it as I said before, or entirely skip the artisan path and clear the view cache in some class that you call from a controller or a route.

But, my real question is do you really need to clear the view cache? In a project I'm working on now, I have almost 100 cached views and they weight less then 1 Mb, while my vendor directory is > 40 Mb. I don't think view cache is a real bottleneck in disk usage and never had a real need to clear it.

As for the application cache, it is stored in the storage/framework/cache directory, but only if you configured the file driver in config/cache.php. You can choose many different drivers, such as Redis or Memcached, to improve performances over a file-based cache.

Laravel - What does php artisan view:clear do?

This command basically just clears out all cached views.

Rather than loading your view every time, a cached copy can be stored in your storage folder. View caching is done because blade compiling each time is a waste of time, as blade obviously turns the template in to a proper PHP file.

By running php artisan view:clear you simply clear out all the cached views, and so next time the blade view is loaded it will be compiled again rather than pulling it from the cache.

im not sure if this effects my view files

This does not effect the views themselves, it simply clears the cached copies.

Will they stay the same?

Your views themselves will stay the same, yes.

Did i remove something important running this command?

Only the cached copies of your views. These will simply be compiled again when the page is loaded.

What are these cache files for?

To prevent blade having to compile every time it is called, it can be done just once to prevent wasting this time.

Will this effect my future work?

Not at all.

How to clear cache in Laravel?

You need to run npm run dev on your development server and npm run prod on your production server, to generate/update the JS and CSS.

If you want clear all cache, stored in /storage/cache:

php artisan cache:clear

And to clear route cache:

php artisan route:clear

To clear view cache:

php artisan view:clear

Laravel 5 how to clear cache using composer.json

With a Filemanager or a Simple PHP Code Delete the compiled views inside of storage\framework\views

Example:

Route::get('/view-clear', function() {
$directory=storage_path('framework/views');
$files=File::allFiles($directory);
File::delete($files);
return '<h1>View cache cleared</h1>';
});


Related Topics



Leave a reply



Submit