function DatabaseStorageExpirable::setWithExpire in Service Container 7.2
Same name in this branch
- 7.2 src/KeyValueStore/DatabaseStorageExpirable.php \Drupal\service_container\KeyValueStore\DatabaseStorageExpirable::setWithExpire()
- 7.2 lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php \Drupal\Core\KeyValueStore\DatabaseStorageExpirable::setWithExpire()
Same name and namespace in other branches
- 7 src/KeyValueStore/DatabaseStorageExpirable.php \Drupal\service_container\KeyValueStore\DatabaseStorageExpirable::setWithExpire()
Saves a value for a given key with a time to live.
Parameters
string $key: The key of the data to store.
mixed $value: The data to store.
int $expire: The time to live for items, in seconds.
Overrides DatabaseStorageExpirable::setWithExpire
File
- src/
KeyValueStore/ DatabaseStorageExpirable.php, line 20 - Contains \Drupal\service_container\KeyValueStore\DatabaseStorageExpirable.
Class
- DatabaseStorageExpirable
- Overrides the KV store from Drupal to call MergeQuery::key instead of ::keys.
Namespace
Drupal\service_container\KeyValueStoreCode
function setWithExpire($key, $value, $expire) {
// We are already writing to the table, so perform garbage collection at
// the end of this request.
$this->needsGarbageCollection = TRUE;
$this->connection
->merge($this->table)
->key(array(
'name' => $key,
'collection' => $this->collection,
))
->fields(array(
'value' => $this->serializer
->encode($value),
'expire' => REQUEST_TIME + $expire,
))
->execute();
}