"Closes #4029 clearCache deletes more files than expected"

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6513 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2008-03-08 04:30:55 +00:00
parent 1a69866df1
commit 7978745056
2 changed files with 84 additions and 44 deletions

View file

@ -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

View file

@ -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');
}
}
?>