From 37278dde9622fc6847328b8bebeadffbeae592a6 Mon Sep 17 00:00:00 2001 From: Genevieve Eddison Date: Thu, 2 Feb 2017 20:55:24 +0800 Subject: [PATCH 1/3] SHQ16-992 implement config switch for cached rates --- src/Helper/CarrierCache.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Helper/CarrierCache.php b/src/Helper/CarrierCache.php index d472b2c3..3fa0eb21 100755 --- a/src/Helper/CarrierCache.php +++ b/src/Helper/CarrierCache.php @@ -51,12 +51,18 @@ class CarrierCache extends \Magento\Framework\App\Helper\AbstractHelper */ protected static $quotesCache = []; + protected $useCache = false; + /** * @param Context $context */ - public function __construct(\Magento\Framework\App\CacheInterface $cache, \Magento\Framework\App\Helper\Context $context) + public function __construct(\Magento\Framework\App\CacheInterface $cache, + \Shipperhq\Shipper\Helper\Data $shipperDataHelper, + \Magento\Framework\App\Helper\Context $context) { $this->cache = $cache; + $this->shipperDataHelper = $shipperDataHelper; + $this->useCache = $this->shipperDataHelper->getConfigValue('carriers/shipper/use_cache'); parent::__construct($context); } @@ -90,9 +96,10 @@ protected function getQuotesCacheKey($requestParams, $carrierCode) public function getCachedQuotes($requestParams, $carrierCode) { $key = $this->getQuotesCacheKey($requestParams, $carrierCode); - // return isset(self::$quotesCache[$key]) ? self::$quotesCache[$key] : null; - $cachedResult = $this->cache->load($key); + $isUse = $this->useCache; + $cachedResult = $this->useCache ? $this->cache->load($key) : $this->useCache; return $cachedResult ? unserialize($cachedResult) : $cachedResult; + } /** @@ -104,9 +111,10 @@ public function getCachedQuotes($requestParams, $carrierCode) */ public function setCachedQuotes($requestParams, $response, $carrierCode) { - $key = $this->getQuotesCacheKey($requestParams, $carrierCode); - $this->cache->save(serialize($response), $key, [self::CACHE_TAG]); - // self::$quotesCache[$key] = $response; + if($this->useCache) { + $key = $this->getQuotesCacheKey($requestParams, $carrierCode); + $this->cache->save(serialize($response), $key, [self::CACHE_TAG]); + } return $this; } From b8c0f4b1412f0360762a9d99a6cc6113b5602074 Mon Sep 17 00:00:00 2001 From: Genevieve Eddison Date: Thu, 2 Feb 2017 21:08:39 +0800 Subject: [PATCH 2/3] SHQ16-992 implement config switch for cached rates --- src/Helper/CarrierCache.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Helper/CarrierCache.php b/src/Helper/CarrierCache.php index 3fa0eb21..a29de982 100755 --- a/src/Helper/CarrierCache.php +++ b/src/Helper/CarrierCache.php @@ -96,7 +96,6 @@ protected function getQuotesCacheKey($requestParams, $carrierCode) public function getCachedQuotes($requestParams, $carrierCode) { $key = $this->getQuotesCacheKey($requestParams, $carrierCode); - $isUse = $this->useCache; $cachedResult = $this->useCache ? $this->cache->load($key) : $this->useCache; return $cachedResult ? unserialize($cachedResult) : $cachedResult; From 2cf596cac230f77b08de609fdad0c3804e275cdc Mon Sep 17 00:00:00 2001 From: Genevieve Eddison Date: Thu, 2 Feb 2017 21:14:30 +0800 Subject: [PATCH 3/3] SHQ16-992 implement config switch for cached rates --- src/Helper/CarrierCache.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Helper/CarrierCache.php b/src/Helper/CarrierCache.php index a29de982..d723473e 100755 --- a/src/Helper/CarrierCache.php +++ b/src/Helper/CarrierCache.php @@ -96,7 +96,10 @@ protected function getQuotesCacheKey($requestParams, $carrierCode) public function getCachedQuotes($requestParams, $carrierCode) { $key = $this->getQuotesCacheKey($requestParams, $carrierCode); - $cachedResult = $this->useCache ? $this->cache->load($key) : $this->useCache; + $cachedResult = false; + if($this->useCache) { + $cachedResult = $this->cache->load($key); + } return $cachedResult ? unserialize($cachedResult) : $cachedResult; }