Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed the Memcache::clear() to not flush all the server, just the var…

…iables associated with the prefix. Refs #1911
  • Loading branch information...
commit 3dd86ebfd4e7142679a843afece955d50c4ab117 1 parent acdfb48
Juan Basso jrbasso authored
24 lib/Cake/Cache/Engine/MemcacheEngine.php
View
@@ -189,10 +189,32 @@ public function delete($key) {
/**
* Delete all keys from the cache
*
+ * @param boolean $check
* @return boolean True if the cache was successfully cleared, false otherwise
*/
public function clear($check) {
- return $this->_Memcache->flush();
+ if ($check) {
+ return true;
+ }
+ foreach ($this->_Memcache->getExtendedStats('slabs') as $slabs) {
+ foreach (array_keys($slabs) as $slabId) {
+ if (!is_numeric($slabId)) {
+ continue;
+ }
+
+ foreach ($this->_Memcache->getExtendedStats('cachedump', $slabId) as $stats) {
+ if (!is_array($stats)) {
+ continue;
+ }
+ foreach (array_keys($stats) as $key) {
+ if (strpos($key, $this->settings['prefix']) === 0) {
+ $this->_Memcache->delete($key);
+ }
+ }
+ }
+ }
+ }
+ return true;
}
/**
15 lib/Cake/Test/Case/Cache/Engine/MemcacheTest.php
View
@@ -344,11 +344,24 @@ public function testConfigurationConflict() {
* @return void
*/
public function testClear() {
- Cache::write('some_value', 'value', 'memcache');
+ Cache::config('memcache2', array(
+ 'engine' => 'Memcache',
+ 'prefix' => 'cake2_',
+ 'duration' => 3600
+ ));
+ Cache::write('some_value', 'cache1', 'memcache');
+ $result = Cache::clear(true, 'memcache');
+ $this->assertTrue($result);
+ $this->assertEquals('cache1', Cache::read('some_value', 'memcache'));
+
+ Cache::write('some_value', 'cache2', 'memcache2');
$result = Cache::clear(false, 'memcache');
$this->assertTrue($result);
$this->assertFalse(Cache::read('some_value', 'memcache'));
+ $this->assertEquals('cache2', Cache::read('some_value', 'memcache2'));
+
+ Cache::clear(false, 'memcache2');
}
/**
* test that a 0 duration can succesfully write.
Please sign in to comment.
Something went wrong with that request. Please try again.