class MemcachedConnection in Memcache API and Integration 8.2
Class MemcachedConnection.
Hierarchy
- class \Drupal\memcache\Connection\MemcachedConnection implements MemcacheConnectionInterface
Expanded class hierarchy of MemcachedConnection
1 file declares its use of MemcachedConnection
- MemcacheDriverFactory.php in src/
Driver/ MemcacheDriverFactory.php
File
- src/
Connection/ MemcachedConnection.php, line 10
Namespace
Drupal\memcache\ConnectionView source
class MemcachedConnection implements MemcacheConnectionInterface {
/**
* The memcache object.
*
* @var \Memcached
*/
protected $memcache;
/**
* Constructs a MemcachedConnection object.
*
* @param \Drupal\memcache\MemcacheSettings $settings
* The memcache config object.
*/
public function __construct(MemcacheSettings $settings) {
$this->memcache = new \Memcached();
$default_opts = [
\Memcached::OPT_COMPRESSION => TRUE,
\Memcached::OPT_DISTRIBUTION => \Memcached::DISTRIBUTION_CONSISTENT,
];
foreach ($default_opts as $key => $value) {
$this->memcache
->setOption($key, $value);
}
// See README.txt for setting custom Memcache options when using the
// memcached PECL extension.
foreach ($settings
->get('options', []) as $key => $value) {
$this->memcache
->setOption($key, $value);
}
// SASL configuration to authenticate with Memcached.
// Note: this only affects the Memcached PECL extension.
if ($sasl_config = $settings
->get('sasl', [])) {
$this->memcache
->setSaslAuthData($sasl_config['username'], $sasl_config['password']);
}
}
/**
* {@inheritdoc}
*/
public function addServer($server_path, $persistent = FALSE) {
list($host, $port) = explode(':', $server_path);
if ($host == 'unix') {
// Memcached expects just the path to the socket without the protocol.
$host = substr($server_path, 7);
// Port is always 0 for unix sockets.
$port = 0;
}
return $this->memcache
->addServer($host, $port, $persistent);
}
/**
* {@inheritdoc}
*/
public function getMemcache() {
return $this->memcache;
}
/**
* {@inheritdoc}
*/
public function close() {
$this->memcache
->quit();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MemcachedConnection:: |
protected | property | The memcache object. | |
MemcachedConnection:: |
public | function |
Adds a memcache server. Overrides MemcacheConnectionInterface:: |
|
MemcachedConnection:: |
public | function |
Closes the memcache instance connection. Overrides MemcacheConnectionInterface:: |
|
MemcachedConnection:: |
public | function |
Returns the internal memcache object. Overrides MemcacheConnectionInterface:: |
|
MemcachedConnection:: |
public | function | Constructs a MemcachedConnection object. |