function DatabaseStorageExpirable::setWithExpireIfNotExists

Implements Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface::setWithExpireIfNotExists().

Overrides KeyValueStoreExpirableInterface::setWithExpireIfNotExists

File

drupal/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php, line 116
Contains Drupal\Core\KeyValueStore\DatabaseStorageExpirable.

Class

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

Namespace

Drupal\Core\KeyValueStore

Code

function setWithExpireIfNotExists($key, $value, $expire) {

  // We are already writing to the table, so perform garbage collection at
  // the end of this request.
  $this->needsGarbageCollection = TRUE;
  $result = $this->connection
    ->merge($this->table)
    ->insertFields(array(
    'collection' => $this->collection,
    'name' => $key,
    'value' => serialize($value),
    'expire' => REQUEST_TIME + $expire,
  ))
    ->condition('collection', $this->collection)
    ->condition('name', $key)
    ->execute();
  return $result == Merge::STATUS_INSERT;
}