/** * @param $key * @param callable $cb * @return mixed|null */ public function get($key, callable $cb) { $item = $this->cache->get($key); if ($item === null) { $item = $cb(); $this->cache->set($key, $item); return $item; } else { return $item; } }
/** * @param $key * @param integer $pregenerateIn */ private function unlock($key, $pregenerateIn = null) { if ($pregenerateIn === null) { $pregenerateIn = $this->pregenerateIn; } $interval = new DateInterval('PT' . $pregenerateIn . 'S'); $regeneratedOn = (new DateTimeImmutable('now'))->add($interval)->format(DateTime::ISO8601); $this->cache->set('sp' . $key, $regeneratedOn); }
/** * @param $key */ public function delete($key) { $this->cache->delete($this->getKey($key)); }