You are here

class CacheBackendFactory in Redis 8

A cache backend factory responsible for the construction of redis cache bins.

Hierarchy

Expanded class hierarchy of CacheBackendFactory

1 string reference to 'CacheBackendFactory'
redis.services.yml in ./redis.services.yml
redis.services.yml
1 service uses CacheBackendFactory
cache.backend.redis in ./redis.services.yml
Drupal\redis\Cache\CacheBackendFactory

File

src/Cache/CacheBackendFactory.php, line 13

Namespace

Drupal\redis\Cache
View source
class CacheBackendFactory implements CacheFactoryInterface {

  /**
   * @var \Drupal\redis\ClientInterface
   */
  protected $clientFactory;

  /**
   * The cache tags checksum provider.
   *
   * @var \Drupal\Core\Cache\CacheTagsChecksumInterface
   */
  protected $checksumProvider;

  /**
   * The serialization class to use.
   *
   * @var \Drupal\Component\Serialization\SerializationInterface
   */
  protected $serializer;

  /**
   * List of cache bins.
   *
   * Renderer and possibly other places fetch backends directly from the
   * factory. Avoid that the backend objects have to fetch meta information like
   * the last delete all timestamp multiple times.
   *
   * @var array
   */
  protected $bins = [];

  /**
   * Creates a redis CacheBackendFactory.
   *
   * @param \Drupal\redis\ClientFactory $client_factory
   * @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider
   * @param \Drupal\redis\Cache\SerializationInterface $serializer
   *   The serialization class to use.
   */
  public function __construct(ClientFactory $client_factory, CacheTagsChecksumInterface $checksum_provider, SerializationInterface $serializer) {
    $this->clientFactory = $client_factory;
    $this->checksumProvider = $checksum_provider;
    $this->serializer = $serializer;
  }

  /**
   * {@inheritdoc}
   */
  public function get($bin) {
    if (!isset($this->bins[$bin])) {
      $class_name = $this->clientFactory
        ->getClass(ClientFactory::REDIS_IMPL_CACHE);
      $this->bins[$bin] = new $class_name($bin, $this->clientFactory
        ->getClient(), $this->checksumProvider, $this->serializer);
    }
    return $this->bins[$bin];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheBackendFactory::$bins protected property List of cache bins.
CacheBackendFactory::$checksumProvider protected property The cache tags checksum provider.
CacheBackendFactory::$clientFactory protected property
CacheBackendFactory::$serializer protected property The serialization class to use.
CacheBackendFactory::get public function Gets a cache backend class for a given cache bin. Overrides CacheFactoryInterface::get
CacheBackendFactory::__construct public function Creates a redis CacheBackendFactory.