function SharedTempStore::set
Same name in other branches
- 9 core/lib/Drupal/Core/TempStore/SharedTempStore.php \Drupal\Core\TempStore\SharedTempStore::set()
- 10 core/lib/Drupal/Core/TempStore/SharedTempStore.php \Drupal\Core\TempStore\SharedTempStore::set()
- 11.x core/lib/Drupal/Core/TempStore/SharedTempStore.php \Drupal\Core\TempStore\SharedTempStore::set()
Stores a particular key/value pair in this SharedTempStore.
Parameters
string $key: The key of the data to store.
mixed $value: The data to store.
Throws
\Drupal\Core\TempStore\TempStoreException Thrown when a lock for the backend storage could not be acquired.
1 call to SharedTempStore::set()
- SharedTempStore::setIfOwner in core/
lib/ Drupal/ Core/ TempStore/ SharedTempStore.php - Stores a particular key/value pair in this SharedTempStore.
File
-
core/
lib/ Drupal/ Core/ TempStore/ SharedTempStore.php, line 198
Class
- SharedTempStore
- Stores and retrieves temporary data for a given owner.
Namespace
Drupal\Core\TempStoreCode
public function set($key, $value) {
if (!$this->lockBackend
->acquire($key)) {
$this->lockBackend
->wait($key);
if (!$this->lockBackend
->acquire($key)) {
throw new TempStoreException("Couldn't acquire lock to update item '{$key}' in '{$this->storage->getCollectionName()}' temporary storage.");
}
}
$value = (object) [
'owner' => $this->owner,
'data' => $value,
'updated' => (int) $this->requestStack
->getMasterRequest()->server
->get('REQUEST_TIME'),
];
$this->storage
->setWithExpire($key, $value, $this->expire);
$this->lockBackend
->release($key);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.