mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Implementing mustRevaidate()
This commit is contained in:
parent
552c70a571
commit
3240f6221e
2 changed files with 53 additions and 0 deletions
|
@ -767,6 +767,29 @@ class CakeResponse {
|
|||
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 @@ class CakeResponseTest extends CakeTestCase {
|
|||
->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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue