Skip to content

Commit

Permalink
Fix: write() after clearGroup() does not actually write to file
Browse files Browse the repository at this point in the history
Although clearGroup() does not use $this->_File, it needs to be null-ed
so that subsequent write() call do not see stale object.
  • Loading branch information
rchavik committed Apr 26, 2013
1 parent 3c036e9 commit 03e5207
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/Cake/Cache/Engine/FileEngine.php
Expand Up @@ -369,6 +369,7 @@ public function clearGroup($group) {
unlink($object->getPathName());
}
}
$this->_File = null;
return true;
}
}
26 changes: 26 additions & 0 deletions lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php
Expand Up @@ -411,6 +411,32 @@ public function testGroupsReadWrite() {
$this->assertTrue(Cache::write('test_groups3', 'value3', 'file_groups'));
}

/**
* Test that clearing with repeat writes works properly
*/
public function testClearingWithRepeatWrites() {
Cache::config('repeat', array(
'engine' => 'File', 'groups' => array('users')
));

$this->assertTrue(Cache::write('user', 'rchavik', 'repeat'));
$this->assertEquals('rchavik', Cache::read('user', 'repeat'));

Cache::delete('user', 'repeat');
$this->assertEquals(false, Cache::read('user', 'repeat'));

$this->assertTrue(Cache::write('user', 'ADmad', 'repeat'));
$this->assertEquals('ADmad', Cache::read('user', 'repeat'));

Cache::clearGroup('users', 'repeat');
$this->assertEquals(false, Cache::read('user', 'repeat'));

$this->assertTrue(Cache::write('user', 'markstory', 'repeat'));
$this->assertEquals('markstory', Cache::read('user', 'repeat'));

Cache::drop('repeat');
}

/**
* Tests that deleting from a groups-enabled config is possible
*
Expand Down

0 comments on commit 03e5207

Please sign in to comment.