Normalize timestamp for expire at

@param null|int|DateInterval $ttl
@return null|int
@throws InvalidArgumentException
541550
public static function normalizeExpireAt($ttl)
    {
        self::checkTtlType($ttl);

        if (is_int($ttl)) {
            return time() + $ttl;
        }

        if ($ttl instanceof DateInterval) {
            $now = new DateTimeImmutable;
            return $now->add($ttl)->getTimestamp();
        }

        return null;
    }
792256
public function calculate_expiry($timestamp) {
        $expiry = null;

        if (isset($this->expiredate)) {
            $expiry = $this->expiredate;
        } else if (isset($this->expireperiod)) {
            $expiry = $timestamp + $this->expireperiod;
        }

        return $expiry;
    }
137971
public function setExpireAt(int $timestamp): bool
    {
        return $this->handle->expireAt($this->name, $timestamp);
    }
1100045
private function _checkExpired($timestamp, $expiration) {
    $result = false;
    if ($expiration !== 0) {
      $timeDiff = time() - $timestamp;
      ($timeDiff > $expiration) ? $result = true : $result = false;
    }
    return $result;
  }
1190644
public function expire($expire)
    {
        if (is_null($expire)) {
            $this->expire = null;
        } elseif (is_numeric($expire) || $expire instanceof DateInterval) {
            $this->expiresAfter($expire);
        } elseif ($expire instanceof DateTimeInterface) {
            $this->expire = $expire;
        } else {
            throw new InvalidArgumentException('not support datetime');
        }

        return $this;
    }
1094113
public function getTtl($listUuid)
    {
        $index = $this->getIndex($listUuid);
        if ($index['ttl'] && $index['ttl'] > 0) {
            $now = new \DateTime('NOW');
            $expire_date = $index['created_on']->add(new \DateInterval('PT'.$index['ttl'].'S'));
            $diffSeconds = $expire_date->getTimestamp() - $now->getTimestamp();

            return $diffSeconds;
        }

        return -1;
    }
95750
protected function fromDefaultTtl($ttl)
    {
        $ttl = (int) $ttl;

        if (0 == $ttl && null !== $this->ttl) {
            $ttl = $this->ttl;
        }
        return $ttl;
    }
1206537
public function set($key, $val, $ttl = null)
    {
        $this->throwInvalidStringArgumentException($key);

        $this->cache[$key] = $val;

        return true;
    }
306149
public function set($key, $value, $ttl)
    {
        $this->initializeOnDemand();

        if (!is_string($key)) {
            throw new InvalidArgumentException(sprintf('Argument #1 must be a string and only, received "%s"', gettype($key)));
        }

        $time = time();

        if ($this->has($key)) {
            $this->cacheMapper->update($key, $value, $ttl);
        } else {
            $this->cacheMapper->insert($key, $value, $ttl, $time);
        }

        // For the current request
        $this->cache[$key] = array(
            ConstProviderInterface::CACHE_PARAM_VALUE => $value,
            ConstProviderInterface::CACHE_PARAM_CREATED_ON => $time,
            ConstProviderInterface::CACHE_PARAM_TTL => $ttl
        );

        return true;
    }
931030
public function save($ttl = 0)
	{
		$ttl = ($ttl)?:$this->ttl;
		if (empty($this->file)) {
			trigger_error('Unable to save. No file specified.');
			return false;
		}
		if(is_null($this->content)) {
			trigger_error(sprintf('Unable to save. Contents of file `%s´ is NULL.',$this->file));
			return false;
		}
		if ($this->changed) {
			$this->fs->write($this->file, (string) $this->content);
			if ($this->f3->get('CACHE')) {
				$cache = \Cache::instance();
				$cacheHash = $this->getCacheHash($this->file);
				if ($this->ttl)
					$cache->set($cacheHash,$this->content,$this->ttl);
				elseif ($cache->exists($cacheHash))
					$cache->clear($cacheHash);
			}
		}
		$this->changed = false;
		$this->metaHandle->save($this->file,$this->meta,$ttl);
		return true;
	}
493901
public RestoreArgs ttl(Duration ttl) {

        LettuceAssert.notNull(ttl, "Time to live must not be null");

        return ttl(ttl.toMillis());
    }
1107669
public function putMany(array $values, $ttl = null)
    {
        if ($ttl === null) {
            return $this->putManyForever($values);
        }

        $seconds = $this->getSeconds($ttl);

        if ($seconds <= 0) {
            return $this->deleteMultiple(array_keys($values));
        }

        $result = $this->store->putMany($values, $seconds);

        if ($result) {
            foreach ($values as $key => $value) {
                $this->event(new KeyWritten($key, $value, $seconds));
            }
        }

        return $result;
    }
584756
public function set($key, $value, $ttl = null)
    {
        $values = $this->readFileContents();

        $values[$key] = [];

        $values[$key][self::VALUE] = $value;
        $values[$key][self::TTL] = $ttl;
        $values[$key][self::CREATE_TIME] = time();

        return $this->writeFileContents($values);
    }
1278104
protected function check_ttl() {
        if ($this->ttl === 0) {
            return 0;
        }
        $maxtime = cache::now() - $this->ttl;
        $count = 0;
        for ($value = reset($this->store); $value !== false; $value = next($this->store)) {
            if ($value[1] >= $maxtime) {
                // We know that elements are sorted by ttl so no need to continue.
                break;
            }
            $count++;
        }
        if ($count) {
            // Remove first $count elements as they are expired.
            $this->store = array_slice($this->store, $count, null, true);
            if ($this->maxsize !== false) {
                $this->storecount -= $count;
            }
        }
        return $count;
    }
615311
public function set($key, $value, $ttl = null)
	{
		return $this->_set($key, $value, $ttl, false);
	}
819448
def expire(self, ttl=None):
        
        if ttl is not None:
            self.database.expire(self.key, ttl)
        else:
            self.database.persist(self.key)
199579
private function getExpiration($ttl) : int
    {
        if ($ttl === null) {
            return PHP_INT_MAX;
        }

        if (is_int($ttl)) {
            return time() + $ttl;
        }

        return (new DateTime())->add($ttl)->getTimestamp();
    }