function DatabaseStorageExpirable::setWithExpireIfNotExists

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php \Drupal\Core\KeyValueStore\DatabaseStorageExpirable::setWithExpireIfNotExists()
  2. 10 core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php \Drupal\Core\KeyValueStore\DatabaseStorageExpirable::setWithExpireIfNotExists()
  3. 11.x core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php \Drupal\Core\KeyValueStore\DatabaseStorageExpirable::setWithExpireIfNotExists()

Overrides KeyValueStoreExpirableInterface::setWithExpireIfNotExists

File

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

Class

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

Namespace

Drupal\Core\KeyValueStore

Code

public function setWithExpireIfNotExists($key, $value, $expire) {
    try {
        return $this->doSetWithExpireIfNotExists($key, $value, $expire);
    } catch (\Exception $e) {
        // If there was an exception, try to create the table.
        if ($this->ensureTableExists()) {
            return $this->doSetWithExpireIfNotExists($key, $value, $expire);
        }
        else {
            throw $e;
        }
    }
}

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