From 3a1bb0c383fcef5c778dac4b097d8de3868439de Mon Sep 17 00:00:00 2001 From: Kevin Robatel Date: Wed, 8 Jan 2020 08:02:58 +0100 Subject: [PATCH] Fix #116 issue about Laravel cache duration in minutes or seconds --- src/Storage/LaravelCacheStorage.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Storage/LaravelCacheStorage.php b/src/Storage/LaravelCacheStorage.php index 1e9d006c..928869a5 100644 --- a/src/Storage/LaravelCacheStorage.php +++ b/src/Storage/LaravelCacheStorage.php @@ -43,8 +43,7 @@ public function fetch($key) public function save($key, CacheEntry $data) { try { - // getTTL returns seconds, Laravel needs minutes - $lifeTime = $data->getTTL() / 60; + $lifeTime = $this->getLifeTime($data); if ($lifeTime === 0) { return $this->cache->forever( $key, @@ -71,4 +70,15 @@ public function delete($key) { return $this->cache->forget($key); } + + protected function getLifeTime(CacheEntry $data) + { + $version = app()->version(); + if (preg_match('/^\d+(\.\d+)?(\.\d+)?/', $version) && version_compare($version, '5.8.0') < 0) { + // getTTL returns seconds, Laravel needs minutes before v5.8 + return $data->getTTL() / 60; + } + + return $data->getTTL(); + } }