/**
  * @param $repository
  * @param $cacheKey
  * @param AbstractApiRequest $request
  * @param int $ttl
  * @return \Commercetools\Core\Model\Common\JsonDeserializeInterface|null
  */
 protected function retrieve($repository, $cacheKey, AbstractApiRequest $request, $force = false, $ttl = self::CACHE_TTL)
 {
     if (!$force && $this->config['cache.' . $repository] && $this->cache->has($cacheKey)) {
         $cachedData = $this->cache->fetch($cacheKey);
         if (empty($cachedData)) {
             throw new NotFoundHttpException("resource not found");
         }
         $result = unserialize($cachedData);
         $result->setContext($this->client->getConfig()->getContext());
     } else {
         $this->profiler->enter($profile = new Profile('retrieve' . ucfirst($repository)));
         $response = $request->executeWithClient($this->client);
         $this->profiler->leave($profile);
         if ($response->isError() || is_null($response->toObject())) {
             $this->store($repository, $cacheKey, '', $ttl);
             throw new NotFoundHttpException("resource not found");
         }
         $result = $request->mapResponse($response);
         $this->store($repository, $cacheKey, serialize($result), $ttl);
     }
     return $result;
 }
 /**
  * @param Client $client
  * @param $cacheKey
  * @param AbstractApiRequest $request
  * @param int $ttl
  * @return \Commercetools\Core\Model\Common\JsonDeserializeInterface|null
  */
 protected function retrieve(Client $client, $cacheKey, AbstractApiRequest $request, $locale, $force = false, $ttl = self::CACHE_TTL)
 {
     if (!$force && $this->enableCache && $this->cache->hasItem($cacheKey)) {
         $cachedData = $this->cache->getItem($cacheKey);
         if (empty($cachedData)) {
             throw new NotFoundHttpException("resource not found");
         }
         $result = unserialize($cachedData->get());
         $result->setContext($client->getConfig()->getContext());
     } else {
         $response = $request->executeWithClient($client);
         if ($response->isError() || is_null($response->toObject())) {
             $this->store($cacheKey, '', $ttl);
             throw new NotFoundHttpException("resource not found");
         }
         $result = $request->mapFromResponse($response, $this->getMapper($locale));
         $this->store($cacheKey, serialize($result), $ttl);
     }
     return $result;
 }