/**
  * @param string $id
  * @param mixed  $data
  * @param int    $lifeTime
  *
  * @return bool|void
  */
 public function save($id, $data, $lifeTime = 0)
 {
     $cacheItem = new CacheItem($id);
     $cacheItem->set($data);
     $cacheItem->expiresAfter($lifeTime === 0 ? null : $lifeTime);
     return $this->cachePool->save($cacheItem);
 }
 /**
  * {@inheritDoc}
  */
 public function getItem($key)
 {
     if (!is_string($key)) {
         throw new InvalidArgumentException("Passed key is invalid");
     }
     $data = $this->cache->fetch($key);
     $item = new CacheItem($key);
     $item->set($data['value']);
     if ($data['expiration'] !== null) {
         $item->expiresAt(new \DateTime($data['expiration']));
     }
     return $item;
 }
示例#3
0
 public function testHit()
 {
     $item = new CacheItem();
     $this->assertFalse($item->isHit());
     $item->set('foobar');
     $this->assertTrue($item->isHit());
     $item->set(null);
     $this->assertTrue($item->isHit());
 }