Skip to content

Commit 2100a64

Browse files
committed
Prefixing group names in XcacheEngine
1 parent ffdd98b commit 2100a64

2 files changed

Lines changed: 23 additions & 8 deletions

File tree

lib/Cake/Cache/Engine/XcacheEngine.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ public function clear($check) {
147147
public function groups() {
148148
$result = array();
149149
foreach ($this->settings['groups'] as $group) {
150-
$value = xcache_get($group);
150+
$value = xcache_get($this->settings['prefix'] . $group);
151151
if (!$value) {
152152
$value = 1;
153-
xcache_set($group, $value, 0);
153+
xcache_set($this->settings['prefix'] . $group, $value, 0);
154154
}
155155
$result[] = $group . $value;
156156
}
@@ -164,7 +164,7 @@ public function groups() {
164164
* @return boolean success
165165
**/
166166
public function clearGroup($group) {
167-
return (bool) xcache_inc($group, 1);
167+
return (bool) xcache_inc($this->settings['prefix'] . $group, 1);
168168
}
169169

170170
/**

lib/Cake/Test/Case/Cache/Engine/XcacheEngineTest.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,16 +207,21 @@ public function testIncrement() {
207207
* @return void
208208
*/
209209
public function testGroupsReadWrite() {
210-
Cache::config('xcache_groups', array('engine' => 'Xcache', 'duration' => 0, 'groups' => array('group_a', 'group_b')));
210+
Cache::config('xcache_groups', array(
211+
'engine' => 'Xcache',
212+
'duration' => 0,
213+
'groups' => array('group_a', 'group_b'),
214+
'prefix' => 'test_'
215+
));
211216
$this->assertTrue(Cache::write('test_groups', 'value', 'xcache_groups'));
212217
$this->assertEquals('value', Cache::read('test_groups', 'xcache_groups'));
213218

214-
xcache_inc('group_a', 1);
219+
xcache_inc('test_group_a', 1);
215220
$this->assertFalse(Cache::read('test_groups', 'xcache_groups'));
216221
$this->assertTrue(Cache::write('test_groups', 'value2', 'xcache_groups'));
217222
$this->assertEquals('value2', Cache::read('test_groups', 'xcache_groups'));
218223

219-
xcache_inc('group_b', 1);
224+
xcache_inc('test_group_b', 1);
220225
$this->assertFalse(Cache::read('test_groups', 'xcache_groups'));
221226
$this->assertTrue(Cache::write('test_groups', 'value3', 'xcache_groups'));
222227
$this->assertEquals('value3', Cache::read('test_groups', 'xcache_groups'));
@@ -228,7 +233,12 @@ public function testGroupsReadWrite() {
228233
* @return void
229234
*/
230235
public function testGroupDelete() {
231-
Cache::config('xcache_groups', array('engine' => 'Xcache', 'duration' => 0, 'groups' => array('group_a', 'group_b')));
236+
Cache::config('xcache_groups', array(
237+
'engine' => 'Xcache',
238+
'duration' => 0,
239+
'groups' => array('group_a', 'group_b'),
240+
'prefix' => 'test_'
241+
));
232242
$this->assertTrue(Cache::write('test_groups', 'value', 'xcache_groups'));
233243
$this->assertEquals('value', Cache::read('test_groups', 'xcache_groups'));
234244
$this->assertTrue(Cache::delete('test_groups', 'xcache_groups'));
@@ -242,7 +252,12 @@ public function testGroupDelete() {
242252
* @return void
243253
**/
244254
public function testGroupClear() {
245-
Cache::config('xcache_groups', array('engine' => 'Xcache', 'duration' => 0, 'groups' => array('group_a', 'group_b')));
255+
Cache::config('xcache_groups', array(
256+
'engine' => 'Xcache',
257+
'duration' => 0,
258+
'groups' => array('group_a', 'group_b'),
259+
'prefix' => 'test_'
260+
));
246261

247262
$this->assertTrue(Cache::write('test_groups', 'value', 'xcache_groups'));
248263
$this->assertTrue(Cache::clearGroup('group_a', 'xcache_groups'));

0 commit comments

Comments
 (0)