function DatabaseStorageExpirable::setWithExpireIfNotExists

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

Overrides KeyValueStoreExpirableInterface::setWithExpireIfNotExists

File

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

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.