Skip to content

Commit 3a1bb0c

Browse files
committed
Fix #116 issue about Laravel cache duration in minutes or seconds
1 parent 7a64679 commit 3a1bb0c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/Storage/LaravelCacheStorage.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ public function fetch($key)
4343
public function save($key, CacheEntry $data)
4444
{
4545
try {
46-
// getTTL returns seconds, Laravel needs minutes
47-
$lifeTime = $data->getTTL() / 60;
46+
$lifeTime = $this->getLifeTime($data);
4847
if ($lifeTime === 0) {
4948
return $this->cache->forever(
5049
$key,
@@ -71,4 +70,15 @@ public function delete($key)
7170
{
7271
return $this->cache->forget($key);
7372
}
73+
74+
protected function getLifeTime(CacheEntry $data)
75+
{
76+
$version = app()->version();
77+
if (preg_match('/^\d+(\.\d+)?(\.\d+)?/', $version) && version_compare($version, '5.8.0') < 0) {
78+
// getTTL returns seconds, Laravel needs minutes before v5.8
79+
return $data->getTTL() / 60;
80+
}
81+
82+
return $data->getTTL();
83+
}
7484
}

0 commit comments

Comments
 (0)