You are here

class CacheFactoryWrapper in Devel 8

Same name and namespace in other branches
  1. 8.3 webprofiler/src/Cache/CacheFactoryWrapper.php \Drupal\webprofiler\Cache\CacheFactoryWrapper
  2. 8.2 webprofiler/src/Cache/CacheFactoryWrapper.php \Drupal\webprofiler\Cache\CacheFactoryWrapper
  3. 4.x webprofiler/src/Cache/CacheFactoryWrapper.php \Drupal\webprofiler\Cache\CacheFactoryWrapper

Wraps a cache factory to register all calls to the cache system.

Hierarchy

  • class \Drupal\webprofiler\Cache\CacheFactoryWrapper implements \Symfony\Component\DependencyInjection\ContainerAwareInterface, CacheFactoryInterface uses \Symfony\Component\DependencyInjection\ContainerAwareTrait

Expanded class hierarchy of CacheFactoryWrapper

1 string reference to 'CacheFactoryWrapper'
webprofiler.services.yml in webprofiler/webprofiler.services.yml
webprofiler/webprofiler.services.yml
1 service uses CacheFactoryWrapper
webprofiler.debug.cache_factory in webprofiler/webprofiler.services.yml
Drupal\webprofiler\Cache\CacheFactoryWrapper

File

webprofiler/src/Cache/CacheFactoryWrapper.php, line 13

Namespace

Drupal\webprofiler\Cache
View source
class CacheFactoryWrapper implements CacheFactoryInterface, ContainerAwareInterface {
  use ContainerAwareTrait;

  /**
   * The cache factory.
   *
   * @var \Drupal\Core\Cache\CacheFactoryInterface
   */
  protected $cacheFactory;

  /**
   * The cache data collector.
   *
   * @var \Drupal\webprofiler\DataCollector\CacheDataCollector
   */
  protected $cacheDataCollector;

  /**
   * All wrapped cache backends.
   *
   * @var \Drupal\webprofiler\Cache\CacheBackendWrapper[]
   */
  protected $cacheBackends = [];

  /**
   * Creates a new CacheFactoryWrapper instance.
   *
   * @param \Drupal\Core\Cache\CacheFactoryInterface $cache_factory
   *   The cache factory.
   * @param \Drupal\webprofiler\DataCollector\CacheDataCollector $cacheDataCollector
   *   The cache data collector.
   */
  public function __construct(CacheFactoryInterface $cache_factory, CacheDataCollector $cacheDataCollector) {
    $this->cacheFactory = $cache_factory;
    $this->cacheDataCollector = $cacheDataCollector;
  }

  /**
   * {@inheritdoc}
   */
  public function get($bin) {
    if (!isset($this->cacheBackends[$bin])) {
      $cache_backend = $this->cacheFactory
        ->get($bin);
      $this->cacheBackends[$bin] = new CacheBackendWrapper($this->cacheDataCollector, $cache_backend, $bin);
    }
    return $this->cacheBackends[$bin];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheFactoryWrapper::$cacheBackends protected property All wrapped cache backends.
CacheFactoryWrapper::$cacheDataCollector protected property The cache data collector.
CacheFactoryWrapper::$cacheFactory protected property The cache factory.
CacheFactoryWrapper::get public function Gets a cache backend class for a given cache bin. Overrides CacheFactoryInterface::get
CacheFactoryWrapper::__construct public function Creates a new CacheFactoryWrapper instance.