Permalink
Browse files

Implmented cache group clearing in Memcache engine

  • Loading branch information...
1 parent d0f7842 commit 6f9d2c01db802ce9a04aa0c7c6b35d200f2c9cd8 @lorenzo lorenzo committed Mar 26, 2012
View
8 lib/Cake/Cache/Engine/MemcacheEngine.php
@@ -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);
}
}
View
21 lib/Cake/Test/Case/Cache/Engine/MemcacheEngineTest.php
@@ -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.