Browse Source

Prefixing group names in XcacheEngine

Jose Lorenzo Rodriguez 14 years ago
parent
commit
2100a64ffd

+ 3 - 3
lib/Cake/Cache/Engine/XcacheEngine.php

@@ -147,10 +147,10 @@ class XcacheEngine extends CacheEngine {
 	public function groups() {
 		$result = array();
 		foreach ($this->settings['groups'] as $group) {
-			$value = xcache_get($group);
+			$value = xcache_get($this->settings['prefix'] . $group);
 			if (!$value) {
 				$value = 1;
-				xcache_set($group, $value, 0);
+				xcache_set($this->settings['prefix'] . $group, $value, 0);
 			}
 			$result[] = $group . $value;
 		}
@@ -164,7 +164,7 @@ class XcacheEngine extends CacheEngine {
  * @return boolean success
  **/
 	public function clearGroup($group) {
-		return (bool) xcache_inc($group, 1);
+		return (bool) xcache_inc($this->settings['prefix'] . $group, 1);
 	}
 
 /**

+ 20 - 5
lib/Cake/Test/Case/Cache/Engine/XcacheEngineTest.php

@@ -207,16 +207,21 @@ class XcacheEngineTest extends CakeTestCase {
  * @return void
  */
 	public function testGroupsReadWrite() {
-		Cache::config('xcache_groups', array('engine' => 'Xcache', 'duration' => 0, 'groups' => array('group_a', 'group_b')));
+		Cache::config('xcache_groups', array(
+			'engine' => 'Xcache',
+			'duration' => 0,
+			'groups' => array('group_a', 'group_b'),
+			'prefix' => 'test_'
+		));
 		$this->assertTrue(Cache::write('test_groups', 'value', 'xcache_groups'));
 		$this->assertEquals('value', Cache::read('test_groups', 'xcache_groups'));
 
-		xcache_inc('group_a', 1);
+		xcache_inc('test_group_a', 1);
 		$this->assertFalse(Cache::read('test_groups', 'xcache_groups'));
 		$this->assertTrue(Cache::write('test_groups', 'value2', 'xcache_groups'));
 		$this->assertEquals('value2', Cache::read('test_groups', 'xcache_groups'));
 
-		xcache_inc('group_b', 1);
+		xcache_inc('test_group_b', 1);
 		$this->assertFalse(Cache::read('test_groups', 'xcache_groups'));
 		$this->assertTrue(Cache::write('test_groups', 'value3', 'xcache_groups'));
 		$this->assertEquals('value3', Cache::read('test_groups', 'xcache_groups'));
@@ -228,7 +233,12 @@ class XcacheEngineTest extends CakeTestCase {
  * @return void
  */
 	public function testGroupDelete() {
-		Cache::config('xcache_groups', array('engine' => 'Xcache', 'duration' => 0, 'groups' => array('group_a', 'group_b')));
+		Cache::config('xcache_groups', array(
+			'engine' => 'Xcache',
+			'duration' => 0,
+			'groups' => array('group_a', 'group_b'),
+			'prefix' => 'test_'
+		));
 		$this->assertTrue(Cache::write('test_groups', 'value', 'xcache_groups'));
 		$this->assertEquals('value', Cache::read('test_groups', 'xcache_groups'));
 		$this->assertTrue(Cache::delete('test_groups', 'xcache_groups'));
@@ -242,7 +252,12 @@ class XcacheEngineTest extends CakeTestCase {
  * @return void
  **/
 	public function testGroupClear() {
-		Cache::config('xcache_groups', array('engine' => 'Xcache', 'duration' => 0, 'groups' => array('group_a', 'group_b')));
+		Cache::config('xcache_groups', array(
+			'engine' => 'Xcache',
+			'duration' => 0,
+			'groups' => array('group_a', 'group_b'),
+			'prefix' => 'test_'
+		));
 
 		$this->assertTrue(Cache::write('test_groups', 'value', 'xcache_groups'));
 		$this->assertTrue(Cache::clearGroup('group_a', 'xcache_groups'));