diff --git a/cake/basics.php b/cake/basics.php index fb3a503fd..4fef4d006 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -611,12 +611,16 @@ if (!function_exists('clone')) { } return true; } else { - $cache = CACHE . $type . DS . '*' . $params . '*' . $ext; + $cache = CACHE . $type . DS . '*' . $params . $ext; $files = glob($cache); + $cache = CACHE . $type . DS . '*' . $params . '_*' . $ext; + $files = array_merge($files, glob($cache)); + if ($files === false) { return false; } + foreach ($files as $file) { if (is_file($file)) { @unlink($file); @@ -626,28 +630,11 @@ if (!function_exists('clone')) { } } elseif (is_array($params)) { foreach ($params as $key => $file) { - $file = preg_replace('/\/\//', '/', $file); - $cache = CACHE . $type . DS . '*' . $file . '*' . $ext; - $files[] = glob($cache); + clearCache($file, $type, $ext); } - - if (!empty($files)) { - foreach ($files as $key => $delete) { - if (is_array($delete)) { - foreach ($delete as $file) { - if (is_file($file)) { - @unlink($file); - } - } - } - } - return true; - } else { - return false; - } - } else { - return false; + return true; } + return false; } /** * Recursively strips slashes from all values in an array diff --git a/cake/tests/cases/libs/cache/file.test.php b/cake/tests/cases/libs/cache/file.test.php index 65abbd42a..ad09210eb 100644 --- a/cake/tests/cases/libs/cache/file.test.php +++ b/cake/tests/cases/libs/cache/file.test.php @@ -106,15 +106,15 @@ class FileEngineTest extends UnitTestCase { function testSerialize() { Cache::engine('File', array('serialize' => true)); $data = 'this is a test of the emergency broadcasting system'; - $write = Cache::write('seriailze_test', $data, 1); + $write = Cache::write('serialize_test', $data, 1); $this->assertTrue($write); Cache::engine('File', array('serialize' => false)); - $read = Cache::read('seriailze_test'); + $read = Cache::read('serialize_test'); - $newread = Cache::read('seriailze_test'); + $newread = Cache::read('serialize_test'); - $delete = Cache::delete('seriailze_test'); + $delete = Cache::delete('serialize_test'); $this->assertIdentical($read, serialize($data)); @@ -124,34 +124,88 @@ class FileEngineTest extends UnitTestCase { function testClear() { $data = 'this is a test of the emergency broadcasting system'; - $write = Cache::write('seriailze_test1', $data, 1); - $write = Cache::write('seriailze_test2', $data, 1); - $write = Cache::write('seriailze_test3', $data, 1); - $this->assertTrue(file_exists(CACHE . 'cake_seriailze_test1')); - $this->assertTrue(file_exists(CACHE . 'cake_seriailze_test2')); - $this->assertTrue(file_exists(CACHE . 'cake_seriailze_test3')); + $write = Cache::write('serialize_test1', $data, 1); + $write = Cache::write('serialize_test2', $data, 1); + $write = Cache::write('serialize_test3', $data, 1); + $this->assertTrue(file_exists(CACHE . 'cake_serialize_test1')); + $this->assertTrue(file_exists(CACHE . 'cake_serialize_test2')); + $this->assertTrue(file_exists(CACHE . 'cake_serialize_test3')); Cache::engine('File', array('duration' => 1)); sleep(4); $result = Cache::clear(true); $this->assertTrue($result); - $this->assertFalse(file_exists(CACHE . 'cake_seriailze_test1')); - $this->assertFalse(file_exists(CACHE . 'cake_seriailze_test2')); - $this->assertFalse(file_exists(CACHE . 'cake_seriailze_test3')); + $this->assertFalse(file_exists(CACHE . 'cake_serialize_test1')); + $this->assertFalse(file_exists(CACHE . 'cake_serialize_test2')); + $this->assertFalse(file_exists(CACHE . 'cake_serialize_test3')); $data = 'this is a test of the emergency broadcasting system'; - $write = Cache::write('seriailze_test1', $data, 1); - $write = Cache::write('seriailze_test2', $data, 1); - $write = Cache::write('seriailze_test3', $data, 1); - $this->assertTrue(file_exists(CACHE . 'cake_seriailze_test1')); - $this->assertTrue(file_exists(CACHE . 'cake_seriailze_test2')); - $this->assertTrue(file_exists(CACHE . 'cake_seriailze_test3')); + $write = Cache::write('serialize_test1', $data, 1); + $write = Cache::write('serialize_test2', $data, 1); + $write = Cache::write('serialize_test3', $data, 1); + $this->assertTrue(file_exists(CACHE . 'cake_serialize_test1')); + $this->assertTrue(file_exists(CACHE . 'cake_serialize_test2')); + $this->assertTrue(file_exists(CACHE . 'cake_serialize_test3')); $result = Cache::clear(); $this->assertTrue($result); - $this->assertFalse(file_exists(CACHE . 'cake_seriailze_test1')); - $this->assertFalse(file_exists(CACHE . 'cake_seriailze_test2')); - $this->assertFalse(file_exists(CACHE . 'cake_seriailze_test3')); + $this->assertFalse(file_exists(CACHE . 'cake_serialize_test1')); + $this->assertFalse(file_exists(CACHE . 'cake_serialize_test2')); + $this->assertFalse(file_exists(CACHE . 'cake_serialize_test3')); + $result = Cache::config('tests', array('engine'=> 'File', 'path' => CACHE . 'views')); + + $data = 'this is a test of the emergency broadcasting system'; + $write = Cache::write('controller_view_1', $data, 1); + $write = Cache::write('controller_view_2', $data, 1); + $write = Cache::write('controller_view_3', $data, 1); + $write = Cache::write('controller_view_10', $data, 1); + $write = Cache::write('controller_view_11', $data, 1); + $write = Cache::write('controller_view_12', $data, 1); + $this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_1')); + $this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_2')); + $this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_3')); + $this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_10')); + $this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_11')); + $this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_12')); + + clearCache('controller_view_1', 'views', ''); + $this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_1')); + $this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_2')); + $this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_3')); + $this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_10')); + $this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_11')); + $this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_12')); + + clearCache('controller_view', 'views', ''); + $this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_1')); + $this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_2')); + $this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_3')); + $this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_10')); + $this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_11')); + $this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_12')); + + $write = Cache::write('controller_view_1', $data, 1); + $write = Cache::write('controller_view_2', $data, 1); + $write = Cache::write('controller_view_3', $data, 1); + $write = Cache::write('controller_view_10', $data, 1); + $write = Cache::write('controller_view_11', $data, 1); + $write = Cache::write('controller_view_12', $data, 1); + $this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_1')); + $this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_2')); + $this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_3')); + $this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_10')); + $this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_11')); + $this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_12')); + + clearCache(array('controller_view_2', 'controller_view_11', 'controller_view_12'), 'views', ''); + $this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_1')); + $this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_2')); + $this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_3')); + $this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_10')); + $this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_11')); + $this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_12')); + + clearCache('controller_view'); } function testKeyPath() { @@ -169,6 +223,5 @@ class FileEngineTest extends UnitTestCase { function tearDown() { Cache::config('default'); } - } ?> \ No newline at end of file