diff --git a/cake/libs/cake_response.php b/cake/libs/cake_response.php index 12eecbeb0..322285d98 100644 --- a/cake/libs/cake_response.php +++ b/cake/libs/cake_response.php @@ -509,6 +509,15 @@ class CakeResponse { * @return void */ 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' + )); } /** diff --git a/cake/tests/cases/libs/cake_response.test.php b/cake/tests/cases/libs/cake_response.test.php index 4bbf1edc7..9a99eb1cf 100644 --- a/cake/tests/cases/libs/cake_response.test.php +++ b/cake/tests/cases/libs/cake_response.test.php @@ -215,4 +215,46 @@ class CakeRequestTestCase extends CakeTestCase { $response->disableCache(); $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); + } } \ No newline at end of file