function CacheFactory::get

Same name in other branches
  1. 9 core/lib/Drupal/Core/Cache/CacheFactory.php \Drupal\Core\Cache\CacheFactory::get()
  2. 10 core/lib/Drupal/Core/Cache/CacheFactory.php \Drupal\Core\Cache\CacheFactory::get()
  3. 11.x core/lib/Drupal/Core/Cache/CacheFactory.php \Drupal\Core\Cache\CacheFactory::get()

Instantiates a cache backend class for a given cache bin.

By default, this returns an instance of the Drupal\Core\Cache\DatabaseBackend class.

Classes implementing Drupal\Core\Cache\CacheBackendInterface can register themselves both as a default implementation and for specific bins.

Parameters

string $bin: The cache bin for which a cache backend object should be returned.

Return value

\Drupal\Core\Cache\CacheBackendInterface The cache backend object associated with the specified bin.

Overrides CacheFactoryInterface::get

File

core/lib/Drupal/Core/Cache/CacheFactory.php, line 65

Class

CacheFactory

Namespace

Drupal\Core\Cache

Code

public function get($bin) {
    $cache_settings = $this->settings
        ->get('cache');
    // First, look for a cache bin specific setting.
    if (isset($cache_settings['bins'][$bin])) {
        $service_name = $cache_settings['bins'][$bin];
    }
    elseif (isset($this->defaultBinBackends[$bin])) {
        $service_name = $this->defaultBinBackends[$bin];
    }
    elseif (isset($cache_settings['default'])) {
        $service_name = $cache_settings['default'];
    }
    else {
        // Fall back to the database backend if nothing else is configured.
        $service_name = 'cache.backend.database';
    }
    return $this->container
        ->get($service_name)
        ->get($bin);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.