Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement withMaxAge()
  • Loading branch information
markstory committed Dec 2, 2016
1 parent 681a387 commit c4bfdbb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/Network/Response.php
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion tests/TestCase/Network/ResponseTest.php
Expand Up @@ -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'));
}

/**
Expand Down

0 comments on commit c4bfdbb

Please sign in to comment.