function DatabaseStorageExpirable::doSetWithExpire

Same name in other branches
  1. 9 core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php \Drupal\Core\KeyValueStore\DatabaseStorageExpirable::doSetWithExpire()
  2. 10 core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php \Drupal\Core\KeyValueStore\DatabaseStorageExpirable::doSetWithExpire()

Saves a value for a given key with a time to live.

This will be called by setWithExpire() within a try block.

Parameters

string $key: The key of the data to store.

mixed $value: The data to store.

int $expire: The time to live for items, in seconds.

1 call to DatabaseStorageExpirable::doSetWithExpire()
DatabaseStorageExpirable::setWithExpire in core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php

File

core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php, line 113

Class

DatabaseStorageExpirable
Defines a default key/value store implementation for expiring items.

Namespace

Drupal\Core\KeyValueStore

Code

protected function doSetWithExpire($key, $value, $expire) {
    $this->connection
        ->merge($this->table)
        ->keys([
        'name' => $key,
        'collection' => $this->collection,
    ])
        ->fields([
        'value' => $this->serializer
            ->encode($value),
        'expire' => $this->time
            ->getRequestTime() + $expire,
    ])
        ->execute();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.