Skip to content

Commit

Permalink
Fix #116 issue about Laravel cache duration in minutes or seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevinrob committed Jan 8, 2020
1 parent 7a64679 commit 3a1bb0c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Storage/LaravelCacheStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -71,4 +70,15 @@ public function delete($key)
{
return $this->cache->forget($key);
}

protected function getLifeTime(CacheEntry $data)
{
$version = app()->version();

This comment has been minimized.

Copy link
@GrahamCampbell

GrahamCampbell Jan 10, 2020

The app function only exists if you install the entire laravel framework.

This comment has been minimized.

Copy link
@GrahamCampbell

GrahamCampbell Jan 10, 2020

Something like this is more robust: madewithlove/illuminate-psr-cache-bridge@e034ad4.

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();
}
}

0 comments on commit 3a1bb0c

Please sign in to comment.