pho*_*ops 11
如果你使用PHP5.5,那么我建议配置opcache php.ini
opcache.revalidate_freq=0
Run Code Online (Sandbox Code Playgroud)
此值设置应从缓存更新视图的时间频率.该值通常为60秒左右.将其设置为0将使您的缓存每次都更新.
我曾经使用过"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)
不是最好的解决方案,但它的工作原理.
您可以尝试此路由过滤器,将 设为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)
希望这对您有所帮助,但我没有测试过,所以我不能保证它会起作用。
| 归档时间: |
|
| 查看次数: |
31129 次 |
| 最近记录: |