Implmented cache group clearing in Memcache engine

This commit is contained in:
Jose Lorenzo Rodriguez 2012-03-25 21:23:27 -04:30
parent d0f7842f36
commit 6f9d2c01db
2 changed files with 28 additions and 1 deletions

View file

@ -262,7 +262,13 @@ class MemcacheEngine extends CacheEngine {
return $result; return $result;
} }
/**
* Increments the group value to simulate deletion of all keys under a group
* old values will remain in sotrage until they expire.
*
* @return boolean success
**/
public function clearGroup($group) { public function clearGroup($group) {
return (bool) $this->_Memcache->increment($group);
} }
} }

View file

@ -451,4 +451,25 @@ class MemcacheEngineTest extends CakeTestCase {
$this->assertFalse(Cache::read('test_groups', 'memcache_groups')); $this->assertFalse(Cache::read('test_groups', 'memcache_groups'));
} }
/**
* Test clearing a cache group
*
* @return void
**/
public function testGroupClear() {
Cache::config('memcache_groups', array(
'engine' => 'Memcache',
'duration' => 3600,
'groups' => array('group_a', 'group_b')
));
$this->assertTrue(Cache::write('test_groups', 'value', 'memcache_groups'));
$this->assertTrue(Cache::clearGroup('group_a', 'memcache_groups'));
$this->assertFalse(Cache::read('test_groups', 'memcache_groups'));
$this->assertTrue(Cache::write('test_groups', 'value2', 'memcache_groups'));
$this->assertTrue(Cache::clearGroup('group_b', 'memcache_groups'));
$this->assertFalse(Cache::read('test_groups', 'memcache_groups'));
}
} }