Skip to content

Commit

Permalink
Fix clearing groups with FileCache and no prefix.
Browse files Browse the repository at this point in the history
If you used FileCache + groups + an empty prefix cached files would not
be cleared as strpos() would fail.
  • Loading branch information
markstory committed Sep 10, 2013
1 parent 5210f83 commit fc2e1fa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/Cake/Cache/Engine/FileEngine.php
Expand Up @@ -415,7 +415,10 @@ public function clearGroup($group) {
$contents = new RecursiveIteratorIterator($directoryIterator, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($contents as $object) {
$containsGroup = strpos($object->getPathName(), DS . $group . DS) !== false;
$hasPrefix = strpos($object->getBaseName(), $this->settings['prefix']) === 0;
$hasPrefix = true;
if (strlen($this->settings['prefix']) !== 0) {
$hasPrefix = strpos($object->getBaseName(), $this->settings['prefix']) === 0;
}
if ($object->isFile() && $containsGroup && $hasPrefix) {
$path = $object->getPathName();
$object = null;
Expand Down
20 changes: 20 additions & 0 deletions lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php
Expand Up @@ -530,4 +530,24 @@ public function testGroupClear() {
$this->assertFalse(Cache::read('test_groups5', 'file_groups2'));
$this->assertEquals('value 3', Cache::read('test_groups6', 'file_groups3'));
}

/**
* Test that clearGroup works with no prefix.
*
* @return void
*/
public function testGroupClearNoPrefix() {
Cache::config('file_groups', array(
'engine' => 'File',
'duration' => 3600,
'prefix' => '',
'groups' => array('group_a', 'group_b')
));
Cache::write('key_1', 'value', 'file_groups');
Cache::write('key_2', 'value', 'file_groups');
Cache::clearGroup('group_a', 'file_groups');
$this->assertFalse(Cache::read('key_1', 'file_groups'), 'Did not delete');
$this->assertFalse(Cache::read('key_2', 'file_groups'), 'Did not delete');
}

}

0 comments on commit fc2e1fa

Please sign in to comment.