class KeyValueChainedFactory in Supercache 8
Same name and namespace in other branches
- 2.0.x src/KeyValueStore/KeyValueChainedFactory.php \Drupal\supercache\KeyValueStore\KeyValueChainedFactory
Defines the key/value store factory for the database backend.
Hierarchy
- class \Drupal\supercache\KeyValueStore\KeyValueChainedFactory implements KeyValueFactoryInterface
Expanded class hierarchy of KeyValueChainedFactory
1 file declares its use of KeyValueChainedFactory
- ChainedStorageTests.php in src/
Tests/ KeyValue/ ChainedStorageTests.php
1 string reference to 'KeyValueChainedFactory'
1 service uses KeyValueChainedFactory
File
- src/
KeyValueStore/ KeyValueChainedFactory.php, line 20 - Contains \Drupal\supercache\KeyValueStore\KeyValueChainedFactory.
Namespace
Drupal\supercache\KeyValueStoreView source
class KeyValueChainedFactory implements KeyValueFactoryInterface {
/**
* The serialization class to use.
*
* @var \Drupal\Component\Serialization\SerializationInterface
*/
protected $serializer;
/**
* The database connection to use.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* Cache backend.
*
* @var CacheFactoryInterface
*/
protected $factory;
/**
* Constructs this factory object.
*
* @param \Drupal\Component\Serialization\SerializationInterface $serializer
* The serialization class to use.
* @param \Drupal\Core\Database\Connection $connection
* The Connection object containing the key-value tables.
*/
function __construct(CacheFactoryInterface $factory, SerializationInterface $serializer, Connection $connection) {
$this->serializer = $serializer;
$this->connection = $connection;
$this->factory = $factory;
}
protected $backed_by_database;
/**
* Not very reliabled but....
* we want to prevent this thing
* from triggering if the cache
* factory is going to return
* us a cache backend that sits
* on top of the database...
*/
function backedByDatabase() {
if (!isset($this->backed_by_database)) {
$this->backed_by_database = $this->factory
->get('test-binary') instanceof \Drupal\Core\Cache\DatabaseBackend;
}
return $this->backed_by_database;
}
/**
* {@inheritdoc}
*/
public function get($collection) {
// Do not chain if the database will
// be taking care of caching.
if ($this
->backedByDatabase()) {
return new \Drupal\Core\KeyValueStore\DatabaseStorage($collection, $this->serializer, $this->connection);
}
return new ChainedStorage($this->factory, $collection, $this->serializer, $this->connection);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
KeyValueChainedFactory:: |
protected | property | ||
KeyValueChainedFactory:: |
protected | property | The database connection to use. | |
KeyValueChainedFactory:: |
protected | property | Cache backend. | |
KeyValueChainedFactory:: |
protected | property | The serialization class to use. | |
KeyValueChainedFactory:: |
function | Not very reliabled but.... we want to prevent this thing from triggering if the cache factory is going to return us a cache backend that sits on top of the database... | ||
KeyValueChainedFactory:: |
public | function |
Constructs a new key/value store for a given collection name. Overrides KeyValueFactoryInterface:: |
|
KeyValueChainedFactory:: |
function | Constructs this factory object. |