You are here

public function DrupalMemcached::__construct in Memcache Storage 8

Builds a new DrupalMemcache(d) object.

Parameters

array $settings: Array of Settings:get('memcache_storage') settings.

$cluster_name: Name of the memcached cluster. Default name is 'default'.

Overrides DrupalMemcachedBase::__construct

File

src/DrupalMemcached.php, line 58

Class

DrupalMemcached
Class DrupalMemcached

Namespace

Drupal\memcache_storage

Code

public function __construct(array $settings, $cluster_name) {
  parent::__construct($settings, $cluster_name);

  // For more info about memcached constants see
  // http://www.php.net/manual/en/memcached.constants.php.
  $this->options = !empty($settings['memcached_options']) ? $settings['memcached_options'] : [];
  $this->options += $this->optionsDefault;

  // Add SASL support.
  // See http://php.net/manual/en/memcached.setsaslauthdata.php
  if (!empty($this->settings['sasl_auth']['user']) && !empty($this->settings['sasl_auth']['password'])) {
    $this->memcached
      ->setSaslAuthData($this->settings['sasl_auth']['user'], $this->settings['sasl_auth']['password']);

    // SASL auth works only with binary protocol.
    $this->options[\Memcached::OPT_BINARY_PROTOCOL] = TRUE;
  }

  // Set pecl memcached options.
  // See http://php.net/manual/en/memcached.setoptions.php
  $this->memcached
    ->setOptions($this->options);
}