Skip to content

Commit

Permalink
FlushViewCache view middleware for local environment.
Browse files Browse the repository at this point in the history
  • Loading branch information
hkp22 committed Sep 20, 2018
1 parent f063970 commit f18928d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/CacheBladeDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ protected function normalizeKey($item, $key = null)
return md5($item);
}

ob_get_clean();

throw new \Exception('Could not determine an appropriate cache key.');
}
}
8 changes: 7 additions & 1 deletion src/CacheLaraViewFragmentServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Illuminate\Contracts\Http\Kernel;


class CacheLaraViewFragmentServiceProvider extends ServiceProvider
{
Expand All @@ -12,8 +14,12 @@ class CacheLaraViewFragmentServiceProvider extends ServiceProvider
*
* @return void
*/
public function boot()
public function boot(Kernel $kernel)
{
if ($this->app->isLocal()) {
$kernel->pushMiddleware('Hkp22\CacheLaraViewFragments\Middleware\FlushViewCache');
}

Blade::directive('cache', function ($expression) {
return "<?php if (! app('Hkp22\CacheLaraViewFragments\CacheBladeDirective')->setUp({$expression})) : ?>";
});
Expand Down
22 changes: 22 additions & 0 deletions src/Middleware/FlushViewCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Hkp22\CacheLaraViewFragments\Middleware;

use Closure;

class FlushViewCache
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
\Cache::tags('views')->flush();

return $next($request);
}
}

0 comments on commit f18928d

Please sign in to comment.