You are here

function DatabaseStorageExpirable::setWithExpireIfNotExists in Service Container 7

Same name and namespace in other branches
  1. 7.2 lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php \Drupal\Core\KeyValueStore\DatabaseStorageExpirable::setWithExpireIfNotExists()

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

Overrides KeyValueStoreExpirableInterface::setWithExpireIfNotExists

File

lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php, line 112
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' => $this->serializer
      ->encode($value),
    'expire' => REQUEST_TIME + $expire,
  ))
    ->condition('collection', $this->collection)
    ->condition('name', $key)
    ->execute();
  return $result == Merge::STATUS_INSERT;
}