You are here

protected function HttpServiceApiWrapperBase::getCachedHttpConfigRequest in HTTP Client Manager 8.2

Get cached HTTP Config Request.

Parameters

\Drupal\http_client_manager\Entity\HttpConfigRequestInterface $request: The HTTP Config Request to be executed.

int $expire: The cache expiry time.

array $tags: An array of cache tags.

Return value

array The Response array.

1 call to HttpServiceApiWrapperBase::getCachedHttpConfigRequest()
HttpServiceApiWrapperBase::httpConfigRequest in src/Plugin/HttpServiceApiWrapper/HttpServiceApiWrapperBase.php
Executes an HTTP Config Request.

File

src/Plugin/HttpServiceApiWrapper/HttpServiceApiWrapperBase.php, line 160

Class

HttpServiceApiWrapperBase
Class HttpServiceApiWrapperBase.

Namespace

Drupal\http_client_manager\Plugin\HttpServiceApiWrapper

Code

protected function getCachedHttpConfigRequest(HttpConfigRequestInterface $request, $expire, array $tags = []) {
  $lang = $this->languageManager
    ->getCurrentLanguage()
    ->getId();
  $cid = self::CACHE_ID_PREFIX . ':' . $request
    ->id() . ':' . $lang;
  if ($cache = $this->cache
    ->get($cid)) {
    return $cache->data;
  }
  try {
    $data = $request
      ->execute()
      ->toArray();
    $this->cache
      ->set($cid, $data, $expire, $tags);
  } catch (CommandException $e) {
    $this
      ->logError($e);
    $data = [];
  }
  return $data;
}