From d837f4cace6940da7f56187ae3940bd58d01e3cb Mon Sep 17 00:00:00 2001 From: Andy Pieters Date: Wed, 16 May 2018 15:32:39 +0200 Subject: [PATCH] getService now also caches the result is an exception is thrown --- src/Api/Transaction/GetService.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Api/Transaction/GetService.php b/src/Api/Transaction/GetService.php index 133bcc82..f7617940 100644 --- a/src/Api/Transaction/GetService.php +++ b/src/Api/Transaction/GetService.php @@ -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; } }