public function testExpiresAfter() { $item = new CacheItem('test_key'); $this->assertNull($item->getExpirationDate()); $item->expiresAfter(null); $this->assertNull($this->getExpectedException()); $item->expiresAfter(new \DateInterval('PT1S')); $this->assertEquals(new \DateTime('+1 second'), $item->getExpirationDate()); $item->expiresAfter(1); $this->assertEquals(new \DateTime('+1 second'), $item->getExpirationDate()); }
/** * @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 CacheUpdate $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 UpdateResult($interception, $key, $annotation->pools); }