title: Cache entire HTML response in Laravel 5
body: <p>I am trying to cache entire response using middleware</p>
  
  <p><strong>Steps i followed</strong></p>
  
  <p><strong>Generated two middleware</strong> </p>
  
  <ul>
  <li>AfterCacheMiddleware</li>
  <li>BeforeCacheMiddleware</li>
  </ul>
  
  <p><strong>With in BeforeCacheMiddleware:</strong></p>
  
  <pre><code>public function handle($request, Closure $next)
  {            
          $key = $request-&gt;url();
          if(Cache::has($key)) return Cache::get($key);
          return $next($request);
  }
  </code></pre>
  
  <p><strong>With in AfterCacheMiddleware</strong></p>
  
  <pre><code>public function handle ($request, Closure $next)
  {       
      $response = $next($request);
      $key = $request-&gt;url();       
      if (!Cache::has($key)) Cache::put($key, $response-&gt;getContent(), 60);
      return $response;
  }
  </code></pre>
  
  <p><strong>Registered middleware in $routeMiddleware array of kernal.php</strong></p>
  
  <pre><code>'cacheafter' =&gt; 'App\Http\Middleware\AfterCacheMiddleware',
  'cachebefore' =&gt; 'App\Http\Middleware\BeforeCacheMiddleware',
  </code></pre>
  
  <p><em>With in routes.php i am calling this dummy routes like this</em></p>
  
  <pre><code>Route::get('middle', ['middleware' =&gt; 'cachebefore', 'cacheafter', function()
  {
      echo "From route";
  }]);
  </code></pre>
  
  <p><strong>Issue:</strong></p>
  
  <p>only <strong>cachebefore</strong> middleware is getting called. cacheafter is not getting called at all</p>
  
  <p>Can anyone suggest what i am missing here ?</p>