function TempStore::set

Stores a particular key/value pair in this TempStore.

Parameters

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

mixed $value: The data to store.

File

drupal/core/modules/user/lib/Drupal/user/TempStore.php, line 137
Contains Drupal\user\TempStore.

Class

TempStore
Stores and retrieves temporary data for a given owner.

Namespace

Drupal\user

Code

function set($key, $value) {
  if (!$this->lockBackend
    ->acquire($key)) {
    $this->lockBackend
      ->wait($key);
    if (!$this->lockBackend
      ->acquire($key)) {
      throw new TempStoreException(format_string("Couldn't acquire lock to update item %key in %collection temporary storage.", array(
        '%key' => $key,
        '%collection' => $this->storage->collection,
      )));
    }
  }
  $value = (object) array(
    'owner' => $this->owner,
    'data' => $value,
    'updated' => REQUEST_TIME,
  );
  $this->storage
    ->setWithExpire($key, $value, $this->expire);
  $this->lockBackend
    ->release($key);
}