From ae57ea7e1b1d8270498b579dc27b964342e258a7 Mon Sep 17 00:00:00 2001 From: Brooke Bryan Date: Tue, 1 Jun 2021 22:19:12 +0100 Subject: [PATCH] Support immutable --- src/Resources/ResourceFactory.php | 2 ++ src/ResponseCacheConfig.php | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Resources/ResourceFactory.php b/src/Resources/ResourceFactory.php index 7bab12e..7aa18f4 100644 --- a/src/Resources/ResourceFactory.php +++ b/src/Resources/ResourceFactory.php @@ -145,6 +145,8 @@ public static function create(DispatchResource $resource, $cache = true) $response->setEtag($resource->getHash()); $response->setPublic(); + $response->setImmutable($cache->isImmutable()); + //This resource should last for 1 year in cache $response->setMaxAge($cache->getCacheSeconds()); $response->setSharedMaxAge($cache->getCacheSeconds()); diff --git a/src/ResponseCacheConfig.php b/src/ResponseCacheConfig.php index effd8c9..1877108 100644 --- a/src/ResponseCacheConfig.php +++ b/src/ResponseCacheConfig.php @@ -5,6 +5,7 @@ class ResponseCacheConfig { protected $_varyHeader = 'Accept-Encoding, Accept'; protected $_cacheSeconds = 31536000; + protected $_immutable = true; /** * @return string @@ -44,4 +45,23 @@ public function setCacheSeconds(int $cacheTimeSeconds) return $this; } + /** + * @return bool + */ + public function isImmutable(): bool + { + return $this->_immutable; + } + + /** + * @param bool $immutable + * + * @return ResponseCacheConfig + */ + public function setImmutable(bool $immutable) + { + $this->_immutable = $immutable; + return $this; + } + }