From 9f1471332d0a331ccd8cec00cb8ac2afd507adc8 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Thu, 5 Jul 2018 23:12:55 +0100 Subject: [PATCH] Make augmentState method more efficient --- .../Middleware/HTTPCacheControlMiddleware.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Control/Middleware/HTTPCacheControlMiddleware.php b/src/Control/Middleware/HTTPCacheControlMiddleware.php index 3bdf2d02b..9d710bf94 100644 --- a/src/Control/Middleware/HTTPCacheControlMiddleware.php +++ b/src/Control/Middleware/HTTPCacheControlMiddleware.php @@ -778,17 +778,16 @@ class HTTPCacheControlMiddleware implements HTTPMiddleware, Resettable */ protected function augmentState(HTTPRequest $request, HTTPResponse $response) { - // If sessions exist we assume that the responses should not be cached by CDNs / proxies as we are - // likely to be supplying information relevant to the current user only - if ($request->getSession()->getAll()) { - // Don't force in case user code chooses to opt in to public caching - $this->privateCache(); - } - // Errors disable cache (unless some errors are cached intentionally by usercode) if ($response->isError() || $response->isRedirect()) { // Even if publicCache(true) is specified, errors will be uncacheable $this->disableCache(true); + } elseif ($request->getSession()->getAll()) { + // If sessions exist we assume that the responses should not be cached by CDNs / proxies as we are + // likely to be supplying information relevant to the current user only + + // Don't force in case user code chooses to opt in to public caching + $this->privateCache(); } } }