/**
  * @param string $key
  * @param mixed $value Using null for the value deletes the key.
  * @param int $ttl Number of seconds until data is automatically deleted. Use 0 for unlimited TTL.
  */
 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;
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function isActive()
 {
     return $this->timer->isPending();
 }