You are here

public function DrupalMemcachedFactory::get in Memcache Storage 8

Returns initialized DrupalMemcache(d) class for the specified cache bin.

Parameters

$bin: The cache bin name.

Return value

object DrupalMemcache(d) object.

File

src/DrupalMemcachedFactory.php, line 75

Class

DrupalMemcachedFactory

Namespace

Drupal\memcache_storage

Code

public function get($bin) {

  // Get the name of the memcached cluster for the specified cache bin.
  $cluster_name = !empty($this->bins_clusters[$bin]) ? $this->bins_clusters[$bin] : 'default';

  // If the connection to the cluster is not initialized yet - then do it!
  if (!isset($this->clusters[$cluster_name])) {

    // Initializes a new DrupalMemcache(d) object.
    // TODO: Switch to services.
    $class_name = 'Drupal\\memcache_storage\\Drupal' . ucfirst(strtolower($this->extension));
    $memcached = new $class_name($this->settings, $cluster_name);

    // Store DrupalMemcache(d) object as a static object, to avoid duplicate
    // connections to the same memcached cluster but for another cache bin.
    $this->clusters[$cluster_name] = $memcached;
  }
  return $this->clusters[$cluster_name];
}