Unverified Commit 62d162fa authored by alexpott's avatar alexpott

Issue #3024452 by kfritsche, hchonov, alexpott:...

Issue #3024452 by kfritsche, hchonov, alexpott: DatabaseStorageExpirable:setWithExpireIfNotExists is not respecting expired
parent 552c6ff5
......@@ -88,17 +88,11 @@ public function setWithExpire($key, $value, $expire) {
* {@inheritdoc}
*/
public function setWithExpireIfNotExists($key, $value, $expire) {
$result = $this->connection->merge($this->table)
->insertFields([
'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;
if (!$this->has($key)) {
$this->setWithExpire($key, $value, $expire);
return TRUE;
}
return FALSE;
}
/**
......
......@@ -22,6 +22,8 @@ public function setWithExpire($key, $value, $expire);
/**
* Sets a value for a given key with a time to live if it does not yet exist.
*
* If a key is expired it also does not exists.
*
* @param string $key
* The key of the data to store.
* @param mixed $value
......
......@@ -153,6 +153,12 @@ public function testExpiration() {
foreach (['troubles', 'still'] as $key) {
$this->assertTrue(!empty($all[$key]));
}
// Test DatabaseStorageExpirable::setWithExpireIfNotExists() will overwrite
// expired items.
$this->assertNull($stores[0]->get('yesterday'));
$stores[0]->setWithExpireIfNotExists('yesterday', 'Oh, yesterday came suddenly', $day);
$this->assertSame('Oh, yesterday came suddenly', $stores[0]->get('yesterday'));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment