Skip to content

Commit

Permalink
Making ApcEngine::clear() only clear keys with a matching
Browse files Browse the repository at this point in the history
prefix. Refs #1911
  • Loading branch information
markstory committed Aug 20, 2011
1 parent 3dd86eb commit ef921fa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/Cake/Cache/Engine/ApcEngine.php
Expand Up @@ -108,10 +108,23 @@ public function delete($key) {
/**
* Delete all keys from the cache. This will clear every cache config using APC.
*
* @param boolean $check If true, nothing will be cleared, as entries are removed
* from APC as they expired. This flag is really only used by FileEngine.
* @return boolean True if the cache was successfully cleared, false otherwise
*/
public function clear($check) {
return apc_clear_cache('user');
if ($check) {
return true;
}
$info = apc_cache_info('user');
$cacheKeys = $info['cache_list'];
unset($info);
foreach ($cacheKeys as $key) {
if (strpos($key['info'], $this->settings['prefix']) === 0) {
apc_delete($key['info']);
}
}
return true;
}

}
3 changes: 3 additions & 0 deletions lib/Cake/Test/Case/Cache/Engine/ApcEngineTest.php
Expand Up @@ -197,10 +197,13 @@ public function testIncrement() {
* @return void
*/
public function testClear() {
apc_store('not_cake', 'survive');
Cache::write('some_value', 'value', 'apc');

$result = Cache::clear(false, 'apc');
$this->assertTrue($result);
$this->assertFalse(Cache::read('some_value', 'apc'));
$this->assertEquals('survive', apc_fetch('not_cake'));
apc_delete('not_cake');
}
}

0 comments on commit ef921fa

Please sign in to comment.