From e4ef83bd2a7599c408ba77b3665f522f84ff8063 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Mon, 18 Jun 2018 10:25:56 +0100 Subject: [PATCH 1/3] FIX Default cache state should be `no-cache` --- src/Control/Middleware/HTTPCacheControlMiddleware.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Control/Middleware/HTTPCacheControlMiddleware.php b/src/Control/Middleware/HTTPCacheControlMiddleware.php index 048303eb1..13608d5e2 100644 --- a/src/Control/Middleware/HTTPCacheControlMiddleware.php +++ b/src/Control/Middleware/HTTPCacheControlMiddleware.php @@ -26,6 +26,8 @@ class HTTPCacheControlMiddleware implements HTTPMiddleware, Resettable const STATE_DISABLED = 'disabled'; + const STATE_DEFAULT = 'default'; + /** * Generate response for the given request * @@ -90,6 +92,9 @@ class HTTPCacheControlMiddleware implements HTTPMiddleware, Resettable self::STATE_ENABLED => [ 'must-revalidate' => true, ], + self::STATE_DEFAULT => [ + 'no-cache' => true, + ], ]; /** @@ -98,7 +103,7 @@ class HTTPCacheControlMiddleware implements HTTPMiddleware, Resettable * @config * @var string */ - protected static $defaultState = self::STATE_DISABLED; + protected static $defaultState = self::STATE_DEFAULT; /** * Current state From b9b1a74b921b0231da5f13445b47599306f4d17a Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Mon, 2 Jul 2018 13:54:11 +0100 Subject: [PATCH 2/3] Make config private (notation isnt working) --- src/Control/Middleware/HTTPCacheControlMiddleware.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Control/Middleware/HTTPCacheControlMiddleware.php b/src/Control/Middleware/HTTPCacheControlMiddleware.php index 13608d5e2..36b2f56ac 100644 --- a/src/Control/Middleware/HTTPCacheControlMiddleware.php +++ b/src/Control/Middleware/HTTPCacheControlMiddleware.php @@ -103,7 +103,7 @@ class HTTPCacheControlMiddleware implements HTTPMiddleware, Resettable * @config * @var string */ - protected static $defaultState = self::STATE_DEFAULT; + private static $defaultState = self::STATE_DEFAULT; /** * Current state From 3116b1f97c7afa23eb4019e5f0a62e0e64da91db Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Mon, 2 Jul 2018 15:13:46 +0100 Subject: [PATCH 3/3] Consolidate disabling cache logic --- src/Control/Middleware/HTTPCacheControlMiddleware.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Control/Middleware/HTTPCacheControlMiddleware.php b/src/Control/Middleware/HTTPCacheControlMiddleware.php index 36b2f56ac..572e6fb2b 100644 --- a/src/Control/Middleware/HTTPCacheControlMiddleware.php +++ b/src/Control/Middleware/HTTPCacheControlMiddleware.php @@ -771,14 +771,9 @@ class HTTPCacheControlMiddleware implements HTTPMiddleware, Resettable } // Errors disable cache (unless some errors are cached intentionally by usercode) - if ($response->isError()) { + if ($response->isError() || $response->isRedirect()) { // Even if publicCache(true) is specified, errors will be uncacheable $this->disableCache(true); } - - // Don't cache redirects - if ($response->isRedirect()) { - $this->disableCache(true); - } } }