mercredi 30 septembre 2015

Cache entire HTML response in Laravel 5

I am trying to cache entire response using middleware

Steps i followed

Generated two middleware

  • AfterCacheMiddleware
  • BeforeCacheMiddleware

With in BeforeCacheMiddleware:

public function handle($request, Closure $next)
{            
        $key = $request->url();
        if(Cache::has($key)) return Cache::get($key);
        return $next($request);
}

With in AfterCacheMiddleware

public function handle ($request, Closure $next)
{       
    $response = $next($request);
    $key = $request->url();       
    if (!Cache::has($key)) Cache::put($key, $response->getContent(), 60);
    return $response;
}

Registered middleware in $routeMiddleware array of kernal.php

'cacheafter' => 'App\Http\Middleware\AfterCacheMiddleware',
'cachebefore' => 'App\Http\Middleware\BeforeCacheMiddleware',

With in routes.php i am calling this dummy routes like this

Route::get('middle', ['middleware' => 'cachebefore', 'cacheafter', function()
{
    echo "From route";
}]);

Issue:

only cachebefore middleware is getting called. cacheafter is not getting called at all

Can anyone suggest what i am missing here ?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1O9qERP
via IFTTT

Aucun commentaire:

Enregistrer un commentaire