diff --git a/lib/Cake/Cache/Engine/ApcEngine.php b/lib/Cake/Cache/Engine/ApcEngine.php index 43fbb72829e..b816b9f21da 100644 --- a/lib/Cake/Cache/Engine/ApcEngine.php +++ b/lib/Cake/Cache/Engine/ApcEngine.php @@ -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; } } diff --git a/lib/Cake/Test/Case/Cache/Engine/ApcEngineTest.php b/lib/Cake/Test/Case/Cache/Engine/ApcEngineTest.php index 9563ace22a2..de2d1bff8b1 100644 --- a/lib/Cake/Test/Case/Cache/Engine/ApcEngineTest.php +++ b/lib/Cake/Test/Case/Cache/Engine/ApcEngineTest.php @@ -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'); } }