Memcache support socket connections and Memcached class

This commit is contained in:
djmaze 2021-08-23 11:34:34 +02:00
parent 4a39093042
commit 881528d2ee
2 changed files with 7 additions and 19 deletions

View file

@ -18,16 +18,6 @@ namespace MailSo\Cache\Drivers;
*/ */
class Memcache implements \MailSo\Cache\DriverInterface class Memcache implements \MailSo\Cache\DriverInterface
{ {
/**
* @var string
*/
private $sHost;
/**
* @var int
*/
private $iPost;
/** /**
* @var int * @var int
*/ */
@ -43,14 +33,12 @@ class Memcache implements \MailSo\Cache\DriverInterface
*/ */
private $sKeyPrefix; private $sKeyPrefix;
function __construct(string $sHost = '127.0.0.1', int $iPost = 11211, int $iExpire = 43200, string $sKeyPrefix = '') function __construct(string $sHost = '127.0.0.1', int $iPort = 11211, int $iExpire = 43200, string $sKeyPrefix = '')
{ {
$this->sHost = $sHost;
$this->iPost = $iPost;
$this->iExpire = 0 < $iExpire ? $iExpire : 43200; $this->iExpire = 0 < $iExpire ? $iExpire : 43200;
$this->oMem = new \Memcache; $this->oMem = \class_exists('Memcache',false) ? new \Memcache : new \Memcached;
if (!$this->oMem->connect($this->sHost, $this->iPost)) if (!$this->oMem->addServer($sHost, $this->iPort))
{ {
$this->oMem = null; $this->oMem = null;
} }

View file

@ -694,11 +694,11 @@ class Actions
break; break;
case ('MEMCACHE' === $sDriver || 'MEMCACHED' === $sDriver) && case ('MEMCACHE' === $sDriver || 'MEMCACHED' === $sDriver) &&
\MailSo\Base\Utils::FunctionExistsAndEnabled('memcache_connect'): (\class_exists('Memcache',false) || \class_exists('Memcached',false)):
$sHost = $this->Config()->Get('labs', 'fast_cache_memcache_host', '127.0.0.1');
$oDriver = new \MailSo\Cache\Drivers\Memcache( $oDriver = new \MailSo\Cache\Drivers\Memcache(
$this->Config()->Get('labs', 'fast_cache_memcache_host', '127.0.0.1'), $sHost,
(int)$this->Config()->Get('labs', 'fast_cache_memcache_port', 11211), strpos($sHost, ':/') ? 0 : (int)$this->Config()->Get('labs', 'fast_cache_memcache_port', 11211),
43200, 43200,
$sKey $sKey
); );