You are here

public function ChainedStorage::__construct in Supercache 8

Same name and namespace in other branches
  1. 2.0.x src/KeyValueStore/ChainedStorage.php \Drupal\supercache\KeyValueStore\ChainedStorage::__construct()

Overrides Drupal\Core\KeyValueStore\StorageBase::__construct().

Parameters

CacheFactoryInterface $factory: The cache backend factory.

string $collection: The name of the collection holding key and value pairs.

\Drupal\Component\Serialization\SerializationInterface $serializer: The serialization class to use.

\Drupal\Core\Database\Connection $connection: The database connection to use.

string $table: The name of the SQL table to use, defaults to key_value.

Overrides DatabaseStorage::__construct

File

src/KeyValueStore/ChainedStorage.php, line 51
Contains \Drupal\supercache\KeyValueStore\ChainedStorage;

Class

ChainedStorage
Defines a chained key value storage that uses any cache backend on top of the database default key/value storage.

Namespace

Drupal\supercache\KeyValueStore

Code

public function __construct(CacheFactoryInterface $factory, $collection, SerializationInterface $serializer, Connection $connection, $table = 'key_value') {
  parent::__construct($collection, $serializer, $connection, $table);

  // Make sure the collection name passed to the cache factory
  // does not have any dots, or else if using database storage it will
  // crash.
  $sanitized_collection = preg_replace('/[^A-Za-z0-9_]+/', '_', $collection);
  $this->cache = $factory
    ->get($table . '_' . $sanitized_collection);
}