3 namespace Drupal\Core\KeyValueStore;
5 use Drupal\Component\Serialization\SerializationInterface;
6 use Drupal\Core\Database\Connection;
9 * Defines the key/value store factory for the database backend.
11 class KeyValueDatabaseExpirableFactory implements KeyValueExpirableFactoryInterface {
14 * Holds references to each instantiation so they can be terminated.
16 * @var \Drupal\Core\KeyValueStore\DatabaseStorageExpirable[]
18 protected $storages = [];
21 * The serialization class to use.
23 * @var \Drupal\Component\Serialization\SerializationInterface
25 protected $serializer;
28 * The database connection.
30 * @var \Drupal\Core\Database\Connection
32 protected $connection;
35 * Constructs this factory object.
37 * @param \Drupal\Component\Serialization\SerializationInterface $serializer
38 * The serialization class to use.
39 * @param \Drupal\Core\Database\Connection $connection
40 * The Connection object containing the key-value tables.
42 public function __construct(SerializationInterface $serializer, Connection $connection) {
43 $this->serializer = $serializer;
44 $this->connection = $connection;
50 public function get($collection) {
51 if (!isset($this->storages[$collection])) {
52 $this->storages[$collection] = new DatabaseStorageExpirable($collection, $this->serializer, $this->connection);
54 return $this->storages[$collection];
58 * Deletes expired items.
60 public function garbageCollection() {
61 $this->connection->delete('key_value_expire')
62 ->condition('expire', REQUEST_TIME, '<')