You are here

public function DrupalMemcachedBase::__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 DrupalMemcachedInterface::__construct

2 calls to DrupalMemcachedBase::__construct()
DrupalMemcache::__construct in src/DrupalMemcache.php
Builds a new DrupalMemcache(d) object.
DrupalMemcached::__construct in src/DrupalMemcached.php
Builds a new DrupalMemcache(d) object.
2 methods override DrupalMemcachedBase::__construct()
DrupalMemcache::__construct in src/DrupalMemcache.php
Builds a new DrupalMemcache(d) object.
DrupalMemcached::__construct in src/DrupalMemcached.php
Builds a new DrupalMemcache(d) object.

File

src/DrupalMemcachedBase.php, line 100

Class

DrupalMemcachedBase
Class DrupalMemcachedBase

Namespace

Drupal\memcache_storage

Code

public function __construct(array $settings, $cluster_name) {

  // Initialize pecl memcache(d) object.
  $this->memcached = new $this->extension();

  // Save settings related to memcache_storage.
  $this->settings = $settings;

  // Save memcached key prefix setting.
  if (!empty($settings['key_prefix'])) {
    $this->keyPrefix = $settings['key_prefix'];
  }

  // Turn on the debug mode.
  if (!empty($settings['debug'])) {
    $this->debug = TRUE;
  }

  // Get the hash algorithm for hashing memcached keys longer than 250 chars.
  // By default sha1 is chosen because it performs quickly with minimal
  // collisions.
  if (!empty($settings['key_hash_algorytm'])) {
    $this->hashAlgorithm = $settings['key_hash_algorytm'];
  }

  // Keep the cluster name.
  $this->cluster = $cluster_name;

  // Get a list of all servers from settings.
  $servers = !empty($this->settings['memcached_servers']) ? $this->settings['memcached_servers'] : $this->serversDefault;

  // Filter servers related to the current cluster.
  foreach ($servers as $server => $name) {
    if ($name == $this->cluster) {
      $this->servers[] = $server;
    }
  }

  // Add servers to the pecl memcache(d) object and return connection
  // status.
  $this->isConnected = $this
    ->addServers($this->servers);
}