mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Implementing CakeResponse::cache()
This commit is contained in:
parent
5ba0e43aa3
commit
8780f0b33d
2 changed files with 51 additions and 0 deletions
|
@ -509,6 +509,15 @@ class CakeResponse {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function cache($since, $time = '+1 day') {
|
public function cache($since, $time = '+1 day') {
|
||||||
|
if (!is_integer($time)) {
|
||||||
|
$time = strtotime($time);
|
||||||
|
}
|
||||||
|
$this->header(array(
|
||||||
|
'Date' => date("D, j M Y G:i:s ", $since) . 'GMT',
|
||||||
|
'Expires' => gmdate("D, j M Y H:i:s", $time) . " GMT",
|
||||||
|
'Cache-Control' => 'cache',
|
||||||
|
'Pragma' => 'cache'
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -215,4 +215,46 @@ class CakeRequestTestCase extends CakeTestCase {
|
||||||
$response->disableCache();
|
$response->disableCache();
|
||||||
$this->assertEquals($response->header(), $expected);
|
$this->assertEquals($response->header(), $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the cache method
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function testCache() {
|
||||||
|
$response = new CakeResponse();
|
||||||
|
$since = time();
|
||||||
|
$time = '+1 day';
|
||||||
|
$expected = array(
|
||||||
|
'Date' => date("D, j M Y G:i:s ", $since) . 'GMT',
|
||||||
|
'Expires' => gmdate("D, j M Y H:i:s", strtotime($time)) . " GMT",
|
||||||
|
'Cache-Control' => 'cache',
|
||||||
|
'Pragma' => 'cache'
|
||||||
|
);
|
||||||
|
$response->cache($since);
|
||||||
|
$this->assertEquals($response->header(), $expected);
|
||||||
|
|
||||||
|
$response = new CakeResponse();
|
||||||
|
$since = time();
|
||||||
|
$time = '+5 day';
|
||||||
|
$expected = array(
|
||||||
|
'Date' => date("D, j M Y G:i:s ", $since) . 'GMT',
|
||||||
|
'Expires' => gmdate("D, j M Y H:i:s", strtotime($time)) . " GMT",
|
||||||
|
'Cache-Control' => 'cache',
|
||||||
|
'Pragma' => 'cache'
|
||||||
|
);
|
||||||
|
$response->cache($since, $time);
|
||||||
|
$this->assertEquals($response->header(), $expected);
|
||||||
|
|
||||||
|
$response = new CakeResponse();
|
||||||
|
$since = time();
|
||||||
|
$time = time();
|
||||||
|
$expected = array(
|
||||||
|
'Date' => date("D, j M Y G:i:s ", $since) . 'GMT',
|
||||||
|
'Expires' => gmdate("D, j M Y H:i:s", $time) . " GMT",
|
||||||
|
'Cache-Control' => 'cache',
|
||||||
|
'Pragma' => 'cache'
|
||||||
|
);
|
||||||
|
$response->cache($since, $time);
|
||||||
|
$this->assertEquals($response->header(), $expected);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue