public function testHit() { $item = new CacheItem('test_key'); $this->assertFalse($item->isHit()); $item->set('foobar'); $this->assertTrue($item->isHit()); $item->set(null); $this->assertTrue($item->isHit()); $item->expiresAfter(5); $this->assertTrue($item->isHit()); $item->expiresAfter(-1); $this->assertFalse($item->isHit()); }
public function testGet() { $item = new CacheItem('test_key'); $this->assertNull($item->get()); $item->set('test'); $this->assertEquals('test', $item->get()); }
/** * @inheritDoc */ public function put(string $key, $value, $expires) : bool { $item = new CacheItem($key); $item->set($value); if (is_int($expires) || $expires instanceof \DateInterval) { $item->expiresAfter($expires); } elseif ($expires instanceof \DateTimeInterface) { // @codeCoverageIgnore $item->expiresAt($expires); } return $this->pool->save($item); }
/** * @param Cacheable $annotation * @param InterceptionSuffixInterface $interception * * @return ResultInterface */ public function interceptSuffix(CacheAnnotationInterface $annotation, InterceptionSuffixInterface $interception) : ResultInterface { if (!$interception->getReturnValue()) { return new EmptyResult(); } $key = $this->calculateKey($annotation, $interception); $item = new CacheItem($key); $item->set($interception->getReturnValue()); $item->setTags($annotation->tags); if ($annotation->ttl > 0) { $item->expiresAfter($annotation->ttl); } foreach ($annotation->pools as $poolName) { $pool = $this->poolManager->getPool($poolName); $pool->save($item); } return new MissResult($interception, $key, $annotation->pools); }