diff --git a/composer.json b/composer.json index 218a9c4..be639d8 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ } ], "require": { - "php": ">=5.6", + "php": ">=7.1", "ext-curl": "*", "ext-json" : "*", "league/oauth2-client": "~2.3" diff --git a/src/Cache/Cache.php b/src/Cache/Cache.php index bffd777..f6d5477 100644 --- a/src/Cache/Cache.php +++ b/src/Cache/Cache.php @@ -33,6 +33,7 @@ public function get($key); * * @param string $key * @param $data + * @param int|null $ttl * @return bool if successful */ public function save($key, $data, ?int $ttl = null); diff --git a/src/Cache/HashTrait.php b/src/Cache/HashTrait.php index 2ea7b6b..79a8d05 100644 --- a/src/Cache/HashTrait.php +++ b/src/Cache/HashTrait.php @@ -39,11 +39,7 @@ public function hash($url, $id, array $headers) */ public function isCachable($url, $httpMethod) { - if ($httpMethod === Client::HTTP_GET && $this->isInitialized()) { - return true; - } - - return false; + return $httpMethod === Client::HTTP_GET && $this->isInitialized(); } /** diff --git a/src/Cache/MemcachedCache.php b/src/Cache/MemcachedCache.php index 622a1f3..5e2ceb3 100644 --- a/src/Cache/MemcachedCache.php +++ b/src/Cache/MemcachedCache.php @@ -59,12 +59,12 @@ public function get($key) } /** - * Save an object. + * Save in cache * - * @param $key + * @param string $key * @param $data - * - * @return bool + * @param int|null $ttl + * @return bool if successful */ public function save($key, $data, ?int $ttl = null) { @@ -90,6 +90,6 @@ public function delete($key) */ public function isInitialized() { - return $this->cache == null; + return $this->cache !== null; } } diff --git a/src/Cache/RedisCache.php b/src/Cache/RedisCache.php index e73f617..cf2bb0d 100644 --- a/src/Cache/RedisCache.php +++ b/src/Cache/RedisCache.php @@ -43,11 +43,26 @@ public function __construct($server = 'localhost', $port = 6379, $ttl = 600, $ti } } + /** + * Get a cached object. + * + * @param $key + * + * @return mixed False is not found + */ public function get($key) { return $this->redis !== null ? $this->redis->get($key) : false; } + /** + * Save in cache + * + * @param string $key + * @param $data + * @param int|null $ttl + * @return bool if successful + */ public function save($key, $data, ?int $ttl = null) { $ttl = $ttl ?? $this->ttl; @@ -55,11 +70,26 @@ public function save($key, $data, ?int $ttl = null) return $this->redis !== null ? $this->redis->setex($key, $ttl, $data) : false; } + /** + * Delete a cached object. + * + * @param $key + * + * @return bool if successful true + */ public function delete($key) { return $this->redis->delete($key) === 1; } + /** + * @return bool + */ + public function isInitialized() + { + return $this->redis !== null; + } + protected function getSerializerValue() { if (defined('HHVM_VERSION')) { @@ -67,12 +97,4 @@ protected function getSerializerValue() } return defined('Redis::SERIALIZER_IGBINARY') ? \Redis::SERIALIZER_IGBINARY : \Redis::SERIALIZER_PHP; } - - /** - * @return bool - */ - public function isInitialized() - { - return $this->redis != null; - } -} \ No newline at end of file +} diff --git a/src/Client/RequestTrait.php b/src/Client/RequestTrait.php index 9c472a6..3f95713 100644 --- a/src/Client/RequestTrait.php +++ b/src/Client/RequestTrait.php @@ -68,8 +68,8 @@ public function makeRequest($relativeUrl, array $variables = array(), $httpMetho $postVariables = $variables; } + if ($this->getCache() !== null && $this->getCache()->isCachable($queryUrl, $httpMethod) && $shouldCache) { - if ($this->getCache() != null && $this->getCache()->isCachable($queryUrl, $httpMethod) && $shouldCache) { $result = $this->getFromCache($queryUrl); if ($result === false) {