Skip to content

Commit 98b14ff

Browse files
committed
Prefixing group names in MemcacheEgine
1 parent 957322e commit 98b14ff

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

lib/Cake/Cache/Engine/MemcacheEngine.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727
*/
2828
class MemcacheEngine extends CacheEngine {
2929

30+
/**
31+
* Contains the compiled group names
32+
* (prefixed witht the global configuration prefix)
33+
*
34+
* @var array
35+
**/
36+
protected $_compiledGroupNames = array();
37+
3038
/**
3139
* Memcache wrapper.
3240
*
@@ -243,9 +251,17 @@ public function connect($host, $port = 11211) {
243251
* @return array
244252
**/
245253
public function groups() {
246-
$groups = $this->_Memcache->get($this->settings['groups']);
247-
if (count($groups) !== count($this->settings['groups'])) {
254+
$groups = $this->_compiledGroupNames;
255+
if (empty($groups)) {
248256
foreach ($this->settings['groups'] as $group) {
257+
$groups[] = $this->settings['prefix'] . $group;
258+
}
259+
$this->_compiledGroupNames = $groups;
260+
}
261+
262+
$groups = $this->_Memcache->get($groups);
263+
if (count($groups) !== count($this->settings['groups'])) {
264+
foreach ($this->_compiledGroupNames as $group) {
249265
if (!isset($groups[$group])) {
250266
$this->_Memcache->set($group, 1, false, 0);
251267
$groups[$group] = 1;
@@ -269,6 +285,6 @@ public function groups() {
269285
* @return boolean success
270286
**/
271287
public function clearGroup($group) {
272-
return (bool) $this->_Memcache->increment($group);
288+
return (bool) $this->_Memcache->increment($this->settings['prefix'] . $group);
273289
}
274290
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,12 +413,13 @@ public function testGroupReadWrite() {
413413
Cache::config('memcache_groups', array(
414414
'engine' => 'Memcache',
415415
'duration' => 3600,
416-
'groups' => array('group_a', 'group_b')
416+
'groups' => array('group_a', 'group_b'),
417+
'prefix' => 'test_'
417418
));
418419
Cache::config('memcache_helper', array(
419420
'engine' => 'Memcache',
420421
'duration' => 3600,
421-
'prefix' => ''
422+
'prefix' => 'test_'
422423
));
423424
$this->assertTrue(Cache::write('test_groups', 'value', 'memcache_groups'));
424425
$this->assertEquals('value', Cache::read('test_groups', 'memcache_groups'));

0 commit comments

Comments
 (0)