/** * Returns a Cache Item representing the specified key. * * This method must always return a CacheItemInterface object, even in case of * a cache miss. It MUST NOT return null. * * @param string $key * The key for which to return the corresponding Cache Item. * * @throws InvalidArgumentException * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException * MUST be thrown. * * @return CacheItemInterface * The corresponding Cache Item. */ public function getItem($key) { Utility::validateKey($key); if (isset($this->_queue[$key])) { return $this->_queue[$key]; } $value = null; $isHit = $this->_cache->isExisting($key); if ($isHit) { $value = $this->_cache->get($key); if ($value instanceof NullObject) { $value = null; } } $item = new CacheItem(); $item->setKey($key); $item->set($value); $item->setIsHit($isHit); return $item; }
public function testSettingInvalidExpirationTime() { $this->expectException(InvalidArgumentException::class); $item = new CacheItem(); $item->expiresAfter('one minute'); }