You are here

protected function DatabaseStorageExpirable::doSetWithExpire in Drupal 10

Same name and namespace in other branches
  1. 9 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.

File

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

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' => REQUEST_TIME + $expire,
  ])
    ->execute();
}