mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Fixed the Memcache::clear() to not flush all the server, just the variables associated with the prefix. Refs #1911
This commit is contained in:
parent
acdfb483a7
commit
3dd86ebfd4
2 changed files with 37 additions and 2 deletions
|
@ -189,10 +189,32 @@ class MemcacheEngine extends CacheEngine {
|
|||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -344,11 +344,24 @@ class MemcacheEngineTest extends CakeTestCase {
|
|||
* @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.
|
||||
|
|
Loading…
Add table
Reference in a new issue