Make augmentState method more efficient

This commit is contained in:
Daniel Hensby 2018-07-05 23:12:55 +01:00 committed by Daniel Hensby
parent 399ebd0031
commit 601bb4d768
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E

View File

@ -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();
}
}
}