如何禁用 Laravel 视图缓存?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25813251/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I disable Laravel view cache?
提问by Benubird
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.
我的一个观点有一个例外。然而,laravel 没有告诉我视图的名称以便我可以找到它并修复它,而是说它在 中app/storage/views/110a3ecc0aa5ab7e6f7f50ef35a67a8b
,这是毫无意义的。
How do I disable this view caching, so that laravel uses and refers to the actual files?
如何禁用此视图缓存,以便 laravel 使用并引用实际文件?
回答by Antonio Carlos Ribeiro
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:
盒子外面?你不能。但是您可以扩展 BladeCompiler 类,覆盖用于检查视图是否已过期的方法:
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:
你需要用你自己的编译器替换 IoC 容器中的 BladeCompiler 实例:
$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
然后你只需要在你的 app/config/view.php 文件中创建那个键
<?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']),
];
回答by veyselsahin
Solution
解决方案
open php.ini
打开 php.ini
opcache.revalidate_freq=0
opcache.fast_shutdown=0
change to this. restart apache.
改成这个。重启阿帕奇。
回答by Joshua Oluikpe
check your .env file Change CACHE_DRIVER=file to CACHE_DRIVER=array
检查您的 .env 文件将 CACHE_DRIVER=file 更改为 CACHE_DRIVER=array
回答by Richard Kersey
this worked for me... added this to the .env file
这对我有用...将其添加到 .env 文件中
CACHE_EXPIRE=-1
回答by zanderwar
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');
}
回答by Prem Sarojanand
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
.
Laravel 创建视图缓存文件,因为它被告知要这样做。在.env
File 中,您会遇到将cache_driver
默认属性file
更改为array
.
回答by suspectus
If you have artisan
, it's easy to clear the cache
如果有artisan
,清除缓存很容易
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
如果你没有或者不想要artisan
(想不通为什么你不想要它,它非常有用),你可以从你的项目的根目录做
cd storage/framework/views/
rm *.php
回答by treanorv
A bit late to the party, however. I had the same issue: the browser not reflecting changes to the php code.
然而,聚会有点晚了。我有同样的问题:浏览器没有反映对 php 代码的更改。
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"
回答by Daud khan
Also try
也试试
composer dump-autoload
回答by Tonio
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,
bootstrap/start.php
$env = $app->detectEnvironment(function(){return 'testing';});
app/config/testing/cache.php
添加到数组中'cache' => false,
app/config/view.php
添加到数组中'cache' => false,