class CacheFactory

Hierarchy

Expanded class hierarchy of CacheFactory

1 string reference to 'CacheFactory'
core.services.yml in drupal/core/core.services.yml
drupal/core/core.services.yml
1 service uses CacheFactory

File

drupal/core/lib/Drupal/Core/Cache/CacheFactory.php, line 17
Contains \Drupal\Core\Cache\CacheFactory.

Namespace

Drupal\Core\Cache
View source
class CacheFactory extends ContainerAware {

  /**
   * The settings array.
   *
   * @var \Drupal\Component\Utility\Settings
   */
  protected $settings;

  /**
   * Constructs CacheFactory object.
   *
   * @param \Drupal\Component\Utility\Settings $settings
   *   The settings array.
   */
  function __construct(Settings $settings) {
    $this->settings = $settings;
  }

  /**
   * 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.
   *
   * @param string $bin
   *   The cache bin for which a cache backend object should be returned.
   *
   * @return \Drupal\Core\Cache\CacheBackendInterface
   *   The cache backend object associated with the specified bin.
   */
  public function get($bin) {
    $cache_settings = $this->settings
      ->get('cache');
    if (isset($cache_settings[$bin])) {
      $service_name = $cache_settings[$bin];
    }
    elseif (isset($cache_settings['default'])) {
      $service_name = $cache_settings['default'];
    }
    else {
      $service_name = 'cache.backend.database';
    }
    return $this->container
      ->get($service_name)
      ->get($bin);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheFactory::$settings protected property The settings array.
CacheFactory::get public function Instantiates a cache backend class for a given cache bin.
CacheFactory::__construct function Constructs CacheFactory object.
ContainerAware::$container protected property @api
ContainerAware::setContainer public function Sets the Container associated with this Controller. Overrides ContainerAwareInterface::setContainer