Browse Source

Making ApcEngine::clear() only clear keys with a matching
prefix. Refs #1911

Mark Story 14 years ago
parent
commit
ef921fa56f

+ 14 - 1
lib/Cake/Cache/Engine/ApcEngine.php

@@ -108,10 +108,23 @@ class ApcEngine extends CacheEngine {
 /**
  * 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 - 0
lib/Cake/Test/Case/Cache/Engine/ApcEngineTest.php

@@ -197,10 +197,13 @@ class ApcEngineTest extends CakeTestCase {
  * @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');
 	}
 }