How do I disable Laravel view cache?

家住魔仙堡 提交于 2019-11-27 00:56:13

问题


I have an exception in one of my views. However, instead of telling me the name of the view so I can find it and fix it, laravel says it is in app/storage/views/110a3ecc0aa5ab7e6f7f50ef35a67a8b, which is meaningless.

How do I disable this view caching, so that laravel uses and refers to the actual files?


回答1:


Out of the box? You can't. But you can extend the BladeCompiler class, overriding the method resposible for checking if the view has been expired:

class MyBladeCompiler extends BladeCompiler {

    public function isExpired($path)
    {
        if ( ! \Config::get('view.cache'))
        {
            return true;
        }

        return parent::isExpired($path);
    }

}

You'll need to replace the BladeCompiler instance in IoC container, with your own compiler:

$app = App::make('app'); // or just $app = app();

$app->bindShared('blade.compiler', function($app)
{
    $cache = $app['path.storage'].'/views';

    return new MyBladeCompiler($app['files'], $cache);
});

And then you just need to create that key in your app/config/view.php file

<?php

return [

    'cache' => false,

    'paths' => [base_path().'/resources/views'],

    'pagination' => 'pagination::slider-3',

];

Or, like I do here:

return [

    'cache' => in_array(App::environment(), ['production', 'staging']),

];



回答2:


Solution

open php.ini

opcache.revalidate_freq=0
opcache.fast_shutdown=0

change to this. restart apache.




回答3:


check your .env file Change CACHE_DRIVER=file to CACHE_DRIVER=array




回答4:


Although some would call this sketchy, this was the quickest and most minimal way to do this on a small application I was working on

On the controller(s) that my routes pointed to:

public function __construct()
{
    exec('php /full/path/to/artisan view:clear');
}



回答5:


this worked for me... added this to the .env file

CACHE_EXPIRE=-1



回答6:


Laravel Creates view cache file because it has been told to do that. In .env File you will come across cache_driver which has default property as file change it to array.




回答7:


If you have artisan, it's easy to clear the cache

php artisan view:clear

If you don't have or don't want artisan (can't think why you wouldn't want it, it's very useful), you can from the root of your project do

cd storage/framework/views/
rm *.php



回答8:


A bit late to the party, however. I had the same issue: the browser not reflecting changes to the php code.

Simple solution for me was:

set the clock on the server to the same time as the dev computer !

sudo date +%T -s "11:14:00"



回答9:


In development environment, I just add and modify the next:

  • bootstrap/start.php

    $env = $app->detectEnvironment(function(){return 'testing';});
    
  • app/config/testing/cache.php add in array

    'cache' => false,
    
  • app/config/view.php add in array

    'cache' => false,
    


来源:https://stackoverflow.com/questions/25813251/how-do-i-disable-laravel-view-cache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!