Skip to content
Permalink
Browse files

Implement withMaxAge()

  • Loading branch information...
markstory committed Dec 2, 2016
1 parent 681a387 commit c4bfdbb21d664f5ee5acd08a771fc5de8d80803b
Showing with 27 additions and 1 deletion.
  1. +18 −0 src/Network/Response.php
  2. +9 −1 tests/TestCase/Network/ResponseTest.php
@@ -1333,6 +1333,24 @@ public function maxAge($seconds = null)
return null;
}
/**
* Create an instance with Cache-Control max-age directive set.
*
* The max-age is the number of seconds after which the response should no longer be considered
* a good candidate to be fetched from the local (client) cache.
*
* @param int $seconds The seconds a cached response can be considered valid
* @return static
*/
public function withMaxAge($seconds)
{
$new = clone $this;
$new->_cacheDirectives['max-age'] = $seconds;
$new->_setCacheControl();
return $new;
}
/**
* Sets the Cache-Control must-revalidate directive.
* must-revalidate indicates that the response should not be served
@@ -879,7 +879,15 @@ public function testMaxAge()
*/
public function testWithMaxAge()
{
$this->markTestIncomplete();
$response = new Response();
$this->assertFalse($response->hasHeader('Cache-Control'));
$new = $response->withMaxAge(3600);
$this->assertEquals('max-age=3600', $new->getHeaderLine('Cache-Control'));
$new = $response->withMaxAge(3600)
->withSharable(false);
$this->assertEquals('max-age=3600, private', $new->getHeaderLine('Cache-Control'));
}
/**

0 comments on commit c4bfdbb

Please sign in to comment.
You can’t perform that action at this time.