DatabaseStorageExpirable example


  public 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() {
    try {
      $this->connection->delete('key_value_expire')
        ->condition('expire', REQUEST_TIME, '<')
        

  protected static $modules = ['system'];

  /** * Tests garbage collection. */
  public function testGarbageCollection() {
    $collection = $this->randomMachineName();
    $connection = Database::getConnection();
    $store = new DatabaseStorageExpirable($collectionnew PhpSerialize()$connection);

    // Insert some items and confirm that they're set.     for ($i = 0; $i <= 3; $i++) {
      $store->setWithExpire('key_' . $i$this->randomObject()rand(500, 100000));
    }
    $this->assertCount(4, $store->getAll(), 'Four items were written to the storage.');

    // Manually expire the data.     for ($i = 0; $i <= 3; $i++) {
      $connection->merge('key_value_expire')
        ->keys([
          
Home | Imprint | This part of the site doesn't use cookies.