public function set(string $key, $value, int $ttl = 0)
{
if (null === $value) {
$this->delete($key);
return;
}
$ttl = (int) $ttl;
if (0 > $ttl) {
$ttl = 0;
}
if (0 !== $ttl) {
$this->ttl[$key] = $ttl;
$this->expire[$key] = time() + $ttl;
$this->queue->insert($key, -$this->expire[$key]);
if (!$this->timer->isPending()) {
$this->timer->start();
}
} else {
unset($this->expire[$key], $this->ttl[$key]);
}
$this->data[$key] = $value;
}