Skip to content

Commit

Permalink
Implmented cache group clearing in Memcache engine
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Mar 26, 2012
1 parent d0f7842 commit 6f9d2c0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/Cake/Cache/Engine/MemcacheEngine.php
Expand Up @@ -262,7 +262,13 @@ public function groups() {
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) {

return (bool) $this->_Memcache->increment($group);
}
}
21 changes: 21 additions & 0 deletions lib/Cake/Test/Case/Cache/Engine/MemcacheEngineTest.php
Expand Up @@ -451,4 +451,25 @@ public function testGroupDelete() {

$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'));
}
}

0 comments on commit 6f9d2c0

Please sign in to comment.