You are here

class KeyValueDatabaseExpirableFactory in Service Container 7

Same name in this branch
  1. 7 src/KeyValueStore/KeyValueDatabaseExpirableFactory.php \Drupal\service_container\KeyValueStore\KeyValueDatabaseExpirableFactory
  2. 7 lib/Drupal/Core/KeyValueStore/KeyValueDatabaseExpirableFactory.php \Drupal\Core\KeyValueStore\KeyValueDatabaseExpirableFactory
Same name and namespace in other branches
  1. 7.2 lib/Drupal/Core/KeyValueStore/KeyValueDatabaseExpirableFactory.php \Drupal\Core\KeyValueStore\KeyValueDatabaseExpirableFactory

Defines the key/value store factory for the database backend.

Hierarchy

Expanded class hierarchy of KeyValueDatabaseExpirableFactory

File

lib/Drupal/Core/KeyValueStore/KeyValueDatabaseExpirableFactory.php, line 17
Contains \Drupal\Core\KeyValueStore\KeyValueDatabaseExpirableFactory.

Namespace

Drupal\Core\KeyValueStore
View source
class KeyValueDatabaseExpirableFactory implements KeyValueExpirableFactoryInterface {

  /**
   * Holds references to each instantiation so they can be terminated.
   *
   * @var \Drupal\Core\KeyValueStore\DatabaseStorageExpirable[]
   */
  protected $storages = array();

  /**
   * 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.
   *
   * @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(SerializationInterface $serializer, Connection $connection) {
    $this->serializer = $serializer;
    $this->connection = $connection;
  }

  /**
   * {@inheritdoc}
   */
  public function get($collection) {
    if (!isset($this->storages[$collection])) {
      $this->storages[$collection] = new DatabaseStorageExpirable($collection, $this->serializer, $this->connection);
    }
    return $this->storages[$collection];
  }

  /**
   * Deletes expired items.
   */
  public function garbageCollection() {
    $this->connection
      ->delete('key_value_expire')
      ->condition('expire', REQUEST_TIME, '<')
      ->execute();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
KeyValueDatabaseExpirableFactory::$connection protected property The database connection.
KeyValueDatabaseExpirableFactory::$serializer protected property The serialization class to use.
KeyValueDatabaseExpirableFactory::$storages protected property Holds references to each instantiation so they can be terminated.
KeyValueDatabaseExpirableFactory::garbageCollection public function Deletes expired items.
KeyValueDatabaseExpirableFactory::get public function Constructs a new expirable key/value store for a given collection name. Overrides KeyValueExpirableFactoryInterface::get 1
KeyValueDatabaseExpirableFactory::__construct function Constructs this factory object.