Skip to content
Permalink
Browse files

Implementing mustRevaidate()

  • Loading branch information...
lorenzo committed Jan 12, 2012
1 parent 552c70a commit 3240f6221eb0ca50fc719c8ed1e1a8bd666756a2
Showing with 53 additions and 0 deletions.
  1. +23 −0 lib/Cake/Network/CakeResponse.php
  2. +30 −0 lib/Cake/Test/Case/Network/CakeResponseTest.php
@@ -767,6 +767,29 @@ public function maxAge($seconds = null) {
return null;
}
/**
* Sets the Cache-Control must-revalidate directive.
* must-revalidate indicates that the response should not be served
* stale by a cache under any cirumstance without first revalidating
* with the origin.
* If called with no parameters, this function will return wheter must-revalidate is present.
*
* @param int $seconds if null, the method will return the current
* must-revalidate value
* @return boolean
*/
public function mustRevalidate($enable = null) {
if ($enable !== null) {
if ($enable) {
$this->_cacheDirectives['must-revalidate'] = null;
} else {
unset($this->_cacheDirectives['must-revalidate']);
}
$this->_setCacheControl();
}
return array_key_exists('must-revalidate', $this->_cacheDirectives);
}
/**
* Helper method to generate a valid Cache-Control header from the options set
* in other methods
@@ -733,4 +733,34 @@ public function testSharedMaxAge() {
->method('_sendHeader')->with('Cache-Control', 's-maxage=3600, public');
$response->send();
}
/**
* Tests setting of must-revalidate Cache-Control directive
*
* @return void
*/
public function testMustRevalidate() {
$response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
$this->assertFalse($response->mustRevalidate());
$response->mustRevalidate(true);
$this->assertTrue($response->mustRevalidate());
$headers = $response->header();
$this->assertEquals('must-revalidate', $headers['Cache-Control']);
$response->expects($this->at(1))
->method('_sendHeader')->with('Cache-Control', 'must-revalidate');
$response->send();
$response->mustRevalidate(false);
$this->assertFalse($response->mustRevalidate());
$response = $this->getMock('CakeResponse', array('_sendHeader', '_sendContent'));
$response->sharedMaxAge(3600);
$response->mustRevalidate(true);
$headers = $response->header();
$this->assertEquals('s-maxage=3600, must-revalidate', $headers['Cache-Control']);
$response->expects($this->at(1))
->method('_sendHeader')->with('Cache-Control', 's-maxage=3600, must-revalidate');
$response->send();
}
}

0 comments on commit 3240f62

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