mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Prefixing group names in XcacheEngine
This commit is contained in:
parent
ffdd98be1b
commit
2100a64ffd
2 changed files with 23 additions and 8 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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'));
|
||||
|
|
Loading…
Add table
Reference in a new issue