194

I notice that Laravel cache views are stored in ~/storage/framework/views. Over time, they get to eat up my space. How do I delete them? Is there any command that could? I tried php artisan cache:clear, but it is not clearing the views cache. With that, I have to manually delete the files in the said folder.

Also, how do I disable the views caching?

Karl Hill
  • 9,745
  • 4
  • 52
  • 77
basagabi
  • 4,598
  • 6
  • 33
  • 78
  • 4
    "Overtime, they get to eat up my space." Unlikely. A large Laravel app I maintain has about 300KB of cached views for about 500 routes. You'll never run out due to cached views on any modern server. – ceejayoz Mar 19 '15 at 19:13
  • 4
    But the problem is that my hosting provider is not limiting by disk space usage. Instead, it is limiting by the number of files that you have. So it is an issue for me. – basagabi Mar 20 '15 at 21:47
  • 9
    That's bizarre, and your couple hundred files in `storage/framework/views` is nothing next to the thousands of files in `vendor`. Get a host that doesn't have absurd insane limitations like that. Limiting by number of files? WTF?! – ceejayoz Mar 20 '15 at 23:26
  • Could you recommend a great hosting for that? Preferably shared hosting. Im not sure if I am allowed to share the name of my current hosting provider. It's a big comany, though. – basagabi Mar 22 '15 at 08:34
  • 1
    I'd go with somewhere like Heroku if you aren't too technical, or Amazon Web Services if you are. If your current host genuinely limits the number of files and not the total used space, they're insane. – ceejayoz Mar 22 '15 at 15:36
  • Some times the problem is on server not Laravel [Prevent http file caching in Apache httpd (MAMP)](http://stackoverflow.com/questions/11532636/prevent-http-file-caching-in-apache-httpd-mamp) –  Oct 31 '16 at 19:48
  • @ceejayoz "Overtime, they get to eat up my space." Likely! My current app has over 500 MB of cached views and growing. – Matt K Jan 22 '18 at 18:24

8 Answers8

331

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

maxxon15
  • 1,469
  • 4
  • 21
  • 34
DilipGurung
  • 3,334
  • 1
  • 10
  • 3
  • Good to know that. One thing I notice, over time, the cache under the views folder gets deleted. Is there something in the code that deletes them in xx days? – basagabi Jul 27 '15 at 11:22
  • I believe it's been around a bit longer than that :) – Oddman Aug 12 '15 at 06:02
37

To get all the artisan command, type...

php artisan

If you want to clear view cache, just use:

php artisan view:clear

If you don't know how to use specific artisan command, just add "help" (see below)

php artisan help view:clear
Tim
  • 4,354
  • 3
  • 30
  • 41
Jake Pucan
  • 628
  • 8
  • 11
18

please try this below command :

sudo php artisan cache:clear

sudo php artisan view:clear

sudo php artisan config:cache
Uddyan Semwal
  • 584
  • 1
  • 6
  • 22
Mosam Prajapati
  • 193
  • 1
  • 6
  • 3
    Maker sure if you `artisan config:cache` that _all_ of your `.env` variables are accessed via `config()`, not `env()` or they'll be null. – FlashJordan Aug 24 '18 at 18:48
  • 1
    @FlashJordan I wish I'd read your comment before running config:cache. lol. For anyone else that runs config:cache as blindly as I did, just delete config.php from bootstrap/cache. – Tarek Adam Oct 30 '18 at 16:36
  • You just saved me tears and sorrow. I have been wondering why my changes haven''t been working. – rotimi-best Apr 17 '21 at 19:22
  • Why use sudo tho? – Adam F Sep 29 '21 at 16:21
9

in Ubuntu system try to run below command:

sudo php artisan cache:clear

sudo php artisan view:clear

sudo php artisan config:cache
Mosam Prajapati
  • 179
  • 2
  • 6
7

To answer your additional question how disable views caching:

You can do this by automatically delete the files in the folder for each request with the command php artisan view:clear mentioned by DilipGurung. Here is an example Middleware class from https://stackoverflow.com/a/38598434/2311074

<?php
namespace App\Http\Middleware;

use Artisan;
use Closure;

class ClearViewCache
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (env('APP_DEBUG') || env('APP_ENV') === 'local') 
            Artisan::call('view:clear');

        return $next($request);
    }
}

However you may note that Larevel will recompile the files in the /app/storage/views folder whenever the time on the views files is earlier than the time on the PHP blade files for the layout. THus, I cannot really think of a scenario where this would be necessary to do.

Adam
  • 20,945
  • 18
  • 119
  • 202
6

Right now there is no view:clear command. For laravel 4 this can probably help you: https://gist.github.com/cjonstrup/8228165

Disabling caching can be done by skipping blade. View caching is done because blade compiling each time is a waste of time.

ArjanSchouten
  • 1,290
  • 8
  • 23
  • I got a good explanation on this here http://stackoverflow.com/questions/31455829/laravel-5-clear-cache-in-shared-hosting-server – Rinto George Jul 19 '15 at 12:38
4

use Below command in terminal

php artisan cache:clear
php artisan route:cache 
php artisan config:cache 
php artisan view:clear
Uddyan Semwal
  • 584
  • 1
  • 6
  • 22
0

Here is a helper that I wrote to solve this issue for my projects. It makes it super simple and easy to be able to clear everything out quickly and with a single command.

https://github.com/Traqza/clear-everything

kray
  • 1,336
  • 2
  • 16
  • 34
  • Take a look at the namespace used. make sure its in the correct folder path, or if youve changed it. make sure you update it accordingly. @samjadps – kray Feb 03 '20 at 17:38
  • I updated the namespace on my end. Should work now for you without doing anything. Just make sure its set in the console/commands folder. – kray Feb 03 '20 at 17:40