Skip to content

Commit

Permalink
getService now also caches the result is an exception is thrown
Browse files Browse the repository at this point in the history
  • Loading branch information
andypieters committed May 16, 2018
1 parent 3690fa1 commit d837f4c
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/Api/Transaction/GetService.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,23 @@ protected function getData()
*/
public function doRequest($endpoint = null, $version = null)
{
if (isset(self::$cache[Config::getServiceId()])) {
Helper::requireApiToken();
Helper::requireServiceId();
return self::$cache[Config::getServiceId()];
}
Helper::requireApiToken();
Helper::requireServiceId();

$result = parent::doRequest('transaction/getService');
self::$cache[Config::getServiceId()] = $result;
$cacheKey = Config::getTokenCode().'|'.Config::getApiToken() . '|' . Config::getServiceId();
if (isset(self::$cache[$cacheKey])) {
if (self::$cache[$cacheKey] instanceof \Exception) {
throw self::$cache[$cacheKey];
}
return self::$cache[$cacheKey];
}
try {
$result = parent::doRequest('transaction/getService');
self::$cache[$cacheKey] = $result;
} catch (\Exception $e) {
self::$cache[$cacheKey] = $e;
throw $e;
}
return $result;
}
}

0 comments on commit d837f4c

Please sign in to comment.