Newer
Older
catch
committed
<?php
/**
* @file
* Contains \Drupal\Core\KeyValueStore\KeyValueDatabaseExpirableFactory.
catch
committed
*/
namespace Drupal\Core\KeyValueStore;
Angie Byron
committed
use Drupal\Component\Serialization\SerializationInterface;
use Drupal\Core\DestructableInterface;
catch
committed
use Drupal\Core\Database\Connection;
/**
* Defines the key/value store factory for the database backend.
*/
Alex Pott
committed
class KeyValueDatabaseExpirableFactory implements KeyValueExpirableFactoryInterface {
/**
* Holds references to each instantiation so they can be terminated.
*
Angie Byron
committed
* @var \Drupal\Core\KeyValueStore\DatabaseStorageExpirable[]
*/
Angie Byron
committed
protected $storages = array();
catch
committed
Angie Byron
committed
/**
* The serialization class to use.
*
* @var \Drupal\Component\Serialization\SerializationInterface
*/
protected $serializer;
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* Constructs this factory object.
*
Angie Byron
committed
* @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.
*/
Angie Byron
committed
function __construct(SerializationInterface $serializer, Connection $connection) {
$this->serializer = $serializer;
$this->connection = $connection;
}
catch
committed
/**
Dries Buytaert
committed
* {@inheritdoc}
catch
committed
*/
public function get($collection) {
Angie Byron
committed
if (!isset($this->storages[$collection])) {
Angie Byron
committed
$this->storages[$collection] = new DatabaseStorageExpirable($collection, $this->serializer, $this->connection);
Angie Byron
committed
}
return $this->storages[$collection];
}
/**
Alex Pott
committed
* Deletes expired items.
*/
Alex Pott
committed
public function garbageCollection() {
$this->connection->delete('key_value_expire')
->condition('expire', REQUEST_TIME, '<')
->execute();