Skip to content

Commit

Permalink
convert time to seconds once (#35721)
Browse files Browse the repository at this point in the history
  • Loading branch information
halaei committed Dec 26, 2020
1 parent 08303c7 commit aae5c4a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Illuminate/Cache/Repository.php
Expand Up @@ -292,17 +292,19 @@ public function setMultiple($values, $ttl = null)
*/
public function add($key, $value, $ttl = null)
{
$seconds = null;

if ($ttl !== null) {
if ($this->getSeconds($ttl) <= 0) {
$seconds = $this->getSeconds($ttl);

if ($seconds <= 0) {
return false;
}

// If the store has an "add" method we will call the method on the store so it
// has a chance to override this logic. Some drivers better support the way
// this operation should work with a total "atomic" implementation of it.
if (method_exists($this->store, 'add')) {
$seconds = $this->getSeconds($ttl);

return $this->store->add(
$this->itemKey($key), $value, $seconds
);
Expand All @@ -313,7 +315,7 @@ public function add($key, $value, $ttl = null)
// so it exists for subsequent requests. Then, we will return true so it is
// easy to know if the value gets added. Otherwise, we will return false.
if (is_null($this->get($key))) {
return $this->put($key, $value, $ttl);
return $this->put($key, $value, $seconds);
}

return false;
Expand Down

0 comments on commit aae5c4a

Please sign in to comment.