Skip to content

Commit

Permalink
Support immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Jun 1, 2021
1 parent 5ef05f8 commit ae57ea7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Resources/ResourceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
20 changes: 20 additions & 0 deletions src/ResponseCacheConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class ResponseCacheConfig
{
protected $_varyHeader = 'Accept-Encoding, Accept';
protected $_cacheSeconds = 31536000;
protected $_immutable = true;

/**
* @return string
Expand Down Expand Up @@ -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;
}

}

0 comments on commit ae57ea7

Please sign in to comment.