Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I disable Laravel view cache?

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?

like image 215
Benubird Avatar asked Sep 12 '14 16:09

Benubird


People also ask

How do I disable cache in Laravel 8?

To disable the cache you have to add the following to your config/cache. php file. 'stores' => [ //... 'none' => [ 'driver' => 'null', ], ], Now you have to change your CACHE_DRIVER value to none in your .

How do I enable Laravel cache?

To enable Laravel caching services, first use the Illuminate\Contracts\Cache\Factory and Illuminate\Contracts\Cache\Repository, as they provide access to the Laravel caching services. The Factory contract gives access to all the cache drivers of your application.


4 Answers

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']),

];
like image 64
Antonio Carlos Ribeiro Avatar answered Oct 17 '22 07:10

Antonio Carlos Ribeiro


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

CACHE_EXPIRE=-1
like image 30
Richard Kersey Avatar answered Oct 17 '22 05:10

Richard Kersey


Solution

open php.ini

opcache.revalidate_freq=0
opcache.fast_shutdown=0

change to this. restart apache.

like image 6
veyselsahin Avatar answered Oct 17 '22 06:10

veyselsahin


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

like image 4
Joshua Oluikpe Avatar answered Oct 17 '22 06:10

Joshua Oluikpe