如何在开发模式下禁用模板缓存?

win*_*ino 26 laravel laravel-4

每当我在模板中更改某些内容时,我都必须手动清除缓存.有没有办法在开发模式下禁用模板缓存?

pho*_*ops 11

如果你使用PHP5.5,那么我建议配置opcache php.ini

opcache.revalidate_freq=0
Run Code Online (Sandbox Code Playgroud)

此值设置应从缓存更新视图的时间频率.该值通常为60秒左右.将其设置为0将使您的缓存每次都更新.


Sim*_*der 6

我曾经使用过"Gadoma"的解决方案.但是由于Laravel 5中没有" filters.php " ,这里是我最新Laravel版本的中间件类:

<?php
namespace App\Http\Middleware;

use Closure;
use Illuminate\Contracts\Routing\Middleware;

class CacheKiller implements Middleware {

    /**
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

        $cachedViewsDirectory = app('path.storage').'/framework/views/';

        if ($handle = opendir($cachedViewsDirectory)) {

            while (false !== ($entry = readdir($handle))) {
                if(strstr($entry, '.')) continue;    
                @unlink($cachedViewsDirectory . $entry);    
            }

            closedir($handle);
        }

        return $next($request);

    }

}
Run Code Online (Sandbox Code Playgroud)

在你的Kernel.php中:

protected $middleware = [
        ...
        'App\Http\Middleware\CacheKiller',
    ];
Run Code Online (Sandbox Code Playgroud)

不是最好的解决方案,但它的工作原理.

  • 将缓存驱动程序更改为本地环境的阵列. (2认同)

Vik*_*eta 6

根据此请求,将应用程序缓存驱动程序更改array本地环境.


Gad*_*oma 1

您可以尝试此路由过滤器,将 设为cache time0,这样您的视图将在每个请求时重新创建:)

这个要点来看

Route::filter('cache', function( $response = null )
{

    $uri = URI::full() == '/' ? 'home' : Str::slug( URI::full() );

    $cached_filename = "response-$uri";

    if ( is_null($response) )
    {
        return Cache::get( $cached_filename );
    }
    else if ( $response->status == 200 )
    {
        $cache_time = 30; // 30 minutes

        if ( $cache_time > 0 ) {
            Cache::put( $cached_filename , $response , $cache_time );
        }
    }

});
Run Code Online (Sandbox Code Playgroud)

希望这对您有所帮助,但我没有测试过,所以我不能保证它会起作用。