Prefixing group names in WincacheEngine

This commit is contained in:
Jose Lorenzo Rodriguez 2012-03-26 23:35:15 -04:30
parent 98b14ff144
commit ffdd98be1b
2 changed files with 38 additions and 8 deletions

View file

@ -26,6 +26,14 @@
*/ */
class WincacheEngine extends CacheEngine { class WincacheEngine extends CacheEngine {
/**
* Contains the compiled group names
* (prefixed witht the global configuration prefix)
*
* @var array
**/
protected $_compiledGroupNames = array();
/** /**
* Initialize the Cache Engine * Initialize the Cache Engine
* *
@ -142,10 +150,17 @@ class WincacheEngine extends CacheEngine {
* @return array * @return array
**/ **/
public function groups() { public function groups() {
$groups = wincache_ucache_get($this->settings['groups']); $groups = $this->_compiledGroupNames;
if (empty($groups)) {
foreach ($this->settings['groups'] as $group) {
$groups[] = $this->settings['prefix'] . $group;
}
$this->_compiledGroupNames = $groups;
}
$groups = wincache_ucache_get($groups);
if (count($groups) !== count($this->settings['groups'])) { if (count($groups) !== count($this->settings['groups'])) {
foreach ($this->settings['groups'] as $group) { foreach ($this->_compiledGroupNames as $group) {
if (!isset($groups[$group])) { if (!isset($groups[$group])) {
wincache_ucache_set($group, 1); wincache_ucache_set($group, 1);
$groups[$group] = 1; $groups[$group] = 1;
@ -168,7 +183,7 @@ class WincacheEngine extends CacheEngine {
* @return boolean success * @return boolean success
**/ **/
public function clearGroup($group) { public function clearGroup($group) {
wincache_ucache_inc($group, 1, $success); wincache_ucache_inc($this->settings['prefix'] . $group, 1, $success);
return $success; return $success;
} }

View file

@ -198,16 +198,21 @@ class WincacheEngineTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testGroupsReadWrite() { public function testGroupsReadWrite() {
Cache::config('wincache_groups', array('engine' => 'Wincache', 'duration' => 0, 'groups' => array('group_a', 'group_b'))); Cache::config('wincache_groups', array(
'engine' => 'Wincache',
'duration' => 0,
'groups' => array('group_a', 'group_b'),
'prefix' => 'test_'
));
$this->assertTrue(Cache::write('test_groups', 'value', 'wincache_groups')); $this->assertTrue(Cache::write('test_groups', 'value', 'wincache_groups'));
$this->assertEquals('value', Cache::read('test_groups', 'wincache_groups')); $this->assertEquals('value', Cache::read('test_groups', 'wincache_groups'));
wincache_ucache_inc('group_a'); wincache_ucache_inc('test_group_a');
$this->assertFalse(Cache::read('test_groups', 'wincache_groups')); $this->assertFalse(Cache::read('test_groups', 'wincache_groups'));
$this->assertTrue(Cache::write('test_groups', 'value2', 'wincache_groups')); $this->assertTrue(Cache::write('test_groups', 'value2', 'wincache_groups'));
$this->assertEquals('value2', Cache::read('test_groups', 'wincache_groups')); $this->assertEquals('value2', Cache::read('test_groups', 'wincache_groups'));
wincache_ucache_inc('group_b'); wincache_ucache_inc('test_group_b');
$this->assertFalse(Cache::read('test_groups', 'wincache_groups')); $this->assertFalse(Cache::read('test_groups', 'wincache_groups'));
$this->assertTrue(Cache::write('test_groups', 'value3', 'wincache_groups')); $this->assertTrue(Cache::write('test_groups', 'value3', 'wincache_groups'));
$this->assertEquals('value3', Cache::read('test_groups', 'wincache_groups')); $this->assertEquals('value3', Cache::read('test_groups', 'wincache_groups'));
@ -219,7 +224,12 @@ class WincacheEngineTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testGroupDelete() { public function testGroupDelete() {
Cache::config('wincache_groups', array('engine' => 'Wincache', 'duration' => 0, 'groups' => array('group_a', 'group_b'))); Cache::config('wincache_groups', array(
'engine' => 'Wincache',
'duration' => 0,
'groups' => array('group_a', 'group_b'),
'prefix' => 'test_'
));
$this->assertTrue(Cache::write('test_groups', 'value', 'wincache_groups')); $this->assertTrue(Cache::write('test_groups', 'value', 'wincache_groups'));
$this->assertEquals('value', Cache::read('test_groups', 'wincache_groups')); $this->assertEquals('value', Cache::read('test_groups', 'wincache_groups'));
$this->assertTrue(Cache::delete('test_groups', 'wincache_groups')); $this->assertTrue(Cache::delete('test_groups', 'wincache_groups'));
@ -233,7 +243,12 @@ class WincacheEngineTest extends CakeTestCase {
* @return void * @return void
**/ **/
public function testGroupClear() { public function testGroupClear() {
Cache::config('wincache_groups', array('engine' => 'Wincache', 'duration' => 0, 'groups' => array('group_a', 'group_b'))); Cache::config('wincache_groups', array(
'engine' => 'Wincache',
'duration' => 0,
'groups' => array('group_a', 'group_b'),
'prefix' => 'test_'
));
$this->assertTrue(Cache::write('test_groups', 'value', 'wincache_groups')); $this->assertTrue(Cache::write('test_groups', 'value', 'wincache_groups'));
$this->assertTrue(Cache::clearGroup('group_a', 'wincache_groups')); $this->assertTrue(Cache::clearGroup('group_a', 'wincache_groups'));