Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Making ApcEngine::clear() only clear keys with a matching

prefix. Refs #1911
  • Loading branch information...
commit ef921fa56f96fb1fb02651aedbe9056d91154bcd 1 parent 3dd86eb
@markstory markstory authored
View
15 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;
}
}
View
3  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');
}
}

0 comments on commit ef921fa

Please sign in to comment.
Something went wrong with that request. Please try again.