Skip to content

Commit 6bde602

Browse files
committed
Attempting to fix issue #445
1 parent b4a6390 commit 6bde602

4 files changed

Lines changed: 35 additions & 9 deletions

File tree

docs/examples/memcache.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@
1717
// Include composer autoloader
1818
require __DIR__ . '/../vendor/autoload.php';
1919

20-
$InstanceCache = CacheManager::getInstance('memcache');
20+
$InstanceCache = CacheManager::getInstance('memcache', ['servers' => [
21+
[
22+
'host' =>'127.0.0.1',
23+
'port' => 11211,
24+
// 'sasl_user' => false, // optional
25+
// 'sasl_password' => false // optional
26+
],
27+
]]);
28+
2129
/**
2230
* In case you need to enable compress_data option:
2331
* $InstanceCache = CacheManager::getInstance('memcache', ['compress_data' => true]);

docs/examples/memcached.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@
1717
// Include composer autoloader
1818
require __DIR__ . '/../vendor/autoload.php';
1919

20-
$InstanceCache = CacheManager::getInstance('memcached');
20+
$InstanceCache = CacheManager::getInstance('memcached', ['servers' => [
21+
[
22+
'host' =>'127.0.0.1',
23+
'port' => 11211,
24+
// 'sasl_user' => false, // optional
25+
// 'sasl_password' => false // optional
26+
],
27+
]]);
28+
2129
/**
2230
* In case you need SASL authentication:
2331
* $InstanceCache = CacheManager::getInstance('memcache', ['sasl_user' => 'hackerman', 'sasl_password' => '12345']);

src/phpFastCache/Drivers/Memcache/Driver.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
/**
2828
* Class Driver
2929
* @package phpFastCache\Drivers
30+
* @property MemcacheSoftware $instance
3031
*/
3132
class Driver implements ExtendedCacheItemPoolInterface
3233
{
@@ -50,7 +51,6 @@ public function __construct(array $config = [])
5051
if (!$this->driverCheck()) {
5152
throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName()));
5253
} else {
53-
$this->instance = new MemcacheSoftware();
5454
$this->driverConnect();
5555

5656
if (array_key_exists('compress_data', $config) && $config[ 'compress_data' ] === true) {
@@ -129,16 +129,21 @@ protected function driverClear()
129129
*/
130130
protected function driverConnect()
131131
{
132-
$servers = (!empty($this->config[ 'memcache' ]) && is_array($this->config[ 'memcache' ]) ? $this->config[ 'memcache' ] : []);
132+
$servers = (!empty($this->config[ 'servers' ]) && is_array($this->config[ 'servers' ]) ? $this->config[ 'servers' ] : []);
133133
if (count($servers) < 1) {
134134
$servers = [
135-
['127.0.0.1', 11211],
135+
[
136+
'host' =>'127.0.0.1',
137+
'port' => 11211,
138+
'sasl_user' => false,
139+
'sasl_password' => false
140+
],
136141
];
137142
}
138143

139144
foreach ($servers as $server) {
140145
try {
141-
if (!$this->instance->addserver($server[ 0 ], $server[ 1 ])) {
146+
if (!$this->instance->addServer($server['host'], $server['port'])) {
142147
$this->fallback = true;
143148
}
144149
if(!empty($server[ 'sasl_user' ]) && !empty($server[ 'sasl_password'])){

src/phpFastCache/Drivers/Memcached/Driver.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,21 @@ protected function driverClear()
128128
*/
129129
protected function driverConnect()
130130
{
131-
$servers = (!empty($this->config[ 'memcache' ]) && is_array($this->config[ 'memcache' ]) ? $this->config[ 'memcache' ] : []);
131+
$servers = (!empty($this->config[ 'servers' ]) && is_array($this->config[ 'servers' ]) ? $this->config[ 'servers' ] : []);
132132
if (count($servers) < 1) {
133133
$servers = [
134-
['127.0.0.1', 11211],
134+
[
135+
'host' =>'127.0.0.1',
136+
'port' => 11211,
137+
'sasl_user' => false,
138+
'sasl_password' => false
139+
],
135140
];
136141
}
137142

138143
foreach ($servers as $server) {
139144
try {
140-
if (!$this->instance->addServer($server[ 0 ], $server[ 1 ])) {
145+
if (!$this->instance->addServer($server['host'], $server['port'])) {
141146
$this->fallback = true;
142147
}
143148
if(!empty($server[ 'sasl_user' ]) && !empty($server[ 'sasl_password'])){

0 commit comments

Comments
 (0)