From f18928dcf0d15180b5d558aa2d99512beebcfb8e Mon Sep 17 00:00:00 2001 From: Harish Kumar Date: Thu, 20 Sep 2018 13:17:50 +0530 Subject: [PATCH] FlushViewCache view middleware for local environment. --- src/CacheBladeDirective.php | 2 ++ src/CacheLaraViewFragmentServiceProvider.php | 8 ++++++- src/Middleware/FlushViewCache.php | 22 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/Middleware/FlushViewCache.php diff --git a/src/CacheBladeDirective.php b/src/CacheBladeDirective.php index 5184ec1..2043764 100644 --- a/src/CacheBladeDirective.php +++ b/src/CacheBladeDirective.php @@ -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.'); } } diff --git a/src/CacheLaraViewFragmentServiceProvider.php b/src/CacheLaraViewFragmentServiceProvider.php index 23fbc70..465ca13 100644 --- a/src/CacheLaraViewFragmentServiceProvider.php +++ b/src/CacheLaraViewFragmentServiceProvider.php @@ -4,6 +4,8 @@ use Illuminate\Support\Facades\Blade; use Illuminate\Support\ServiceProvider; +use Illuminate\Contracts\Http\Kernel; + class CacheLaraViewFragmentServiceProvider extends ServiceProvider { @@ -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 "setUp({$expression})) : ?>"; }); diff --git a/src/Middleware/FlushViewCache.php b/src/Middleware/FlushViewCache.php new file mode 100644 index 0000000..f430447 --- /dev/null +++ b/src/Middleware/FlushViewCache.php @@ -0,0 +1,22 @@ +flush(); + + return $next($request); + } +}