Skip to content

Commit

Permalink
Add withSharedMaxAge()
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Dec 5, 2016
1 parent 4f75c34 commit 986efd0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Network/Response.php
Expand Up @@ -1331,6 +1331,24 @@ public function sharedMaxAge($seconds = null)
return null;
}

/**
* Create a new instance with the Cache-Control s-maxage directive.
*
* The max-age is the number of seconds after which the response should no longer be considered
* a good candidate to be fetched from a shared cache (like in a proxy server).
*
* @param int $seconds The number of seconds for shared max-age
* @return static
*/
public function withSharedMaxAge($seconds)
{
$new = clone $this;
$new->_cacheDirectives['s-maxage'] = $seconds;
$new->_setCacheControl();

return $new;
}

/**
* Sets the Cache-Control max-age directive.
* The max-age is the number of seconds after which the response should no longer be considered
Expand Down
17 changes: 17 additions & 0 deletions tests/TestCase/Network/ResponseTest.php
Expand Up @@ -980,6 +980,23 @@ public function testSharedMaxAge()
$this->assertEquals('s-maxage=3600, public', $response->getHeaderLine('Cache-Control'));
}

/**
* Tests setting of s-maxage Cache-Control directive
*
* @return void
*/
public function testWithSharedMaxAge()
{
$response = new Response();
$new = $response->withSharedMaxAge(3600);

$this->assertFalse($response->hasHeader('Cache-Control'));
$this->assertEquals('s-maxage=3600', $new->getHeaderLine('Cache-Control'));

$new = $response->withSharedMaxAge(3600)->withSharable(true);
$this->assertEquals('s-maxage=3600, public', $new->getHeaderLine('Cache-Control'));
}

/**
* Tests setting of must-revalidate Cache-Control directive
*
Expand Down

0 comments on commit 986efd0

Please sign in to comment.