示例#1
0
 /**
  * @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;
     }
 }
示例#2
0
 /**
  * @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);
 }
示例#3
0
 /**
  * @param $key
  * @param $value
  */
 public function set($key, $value)
 {
     $this->cache->set($this->getKey($key), $value);
 }