function it_checks_if_item_exists_in_cache_without_creating_cache_item()
 {
     $this->cacheFrontend->load('prefix_key1')->willReturn(serialize('test'));
     $this->cacheFrontend->load('prefix_key2')->willReturn(false);
     $this->cacheItemFactory->create(Argument::any())->shouldNotBeCalled();
     $this->hasItem('key1')->shouldReturn(true);
     $this->hasItem('key2')->shouldReturn(false);
 }
Ejemplo n.º 2
0
 /**
  * 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)
 {
     $cacheEntry = $this->cacheFrontend->load($this->prepareKey($key));
     if ($cacheEntry !== false) {
         $cacheEntry = unserialize($cacheEntry);
         return $this->cacheItemFactory->create(['key' => $key, 'isHit' => true, 'value' => $cacheEntry]);
     }
     return $this->cacheItemFactory->create(['key' => $key, 'isHit' => false]);
 }