You are here

protected function MemcacheDriverFactory::initialize in Memcache API and Integration 8.2

Initializes memcache settings.

1 call to MemcacheDriverFactory::initialize()
MemcacheDriverFactory::__construct in src/Driver/MemcacheDriverFactory.php
Constructs a MemcacheDriverFactory object.

File

src/Driver/MemcacheDriverFactory.php, line 157

Class

MemcacheDriverFactory
Factory class for creation of Memcache objects.

Namespace

Drupal\memcache\Driver

Code

protected function initialize() {

  // If an extension is specified in settings.php, use that when available.
  $preferred = $this->settings
    ->get('extension', NULL);
  if (isset($preferred) && class_exists($preferred)) {
    $extension = $preferred;
  }
  elseif (class_exists('Memcached')) {
    $extension = \Memcached::class;
  }
  elseif (class_exists('Memcache')) {
    $extension = \Memcache::class;
  }
  else {
    throw new MemcacheException('No Memcache extension found');
  }

  // @todo Make driver class configurable?
  $this->connectionClass = MemcachedConnection::class;
  $this->driverClass = MemcachedDriver::class;
  if ($extension === \Memcache::class) {
    $this->connectionClass = MemcacheConnection::class;
    $this->driverClass = MemcacheDriver::class;
  }

  // Values from settings.php.
  $this->servers = $this->settings
    ->get('servers', [
    '127.0.0.1:11211' => 'default',
  ]);
  $this->bins = $this->settings
    ->get('bins', [
    'default' => 'default',
  ]);

  // Indicate whether to connect to memcache using a persistent connection.
  // Note: this only affects the Memcache PECL extension, and does not affect
  // the Memcached PECL extension.  For a detailed explanation see:
  // http://drupal.org/node/822316#comment-4427676
  $this->persistent = $this->settings
    ->get('persistent', FALSE);
}