Skip to content

Commit

Permalink
Fix subscriptions storage manager TTL (#1307)
Browse files Browse the repository at this point in the history
The TTL argument on cache calls is in minutes in Laravel 5.5-5.7 and changed to seconds on Laravel 5.8+, passing a Carbon instance makes sure our TTL in seconds is always correct.
  • Loading branch information
stayallive authored and spawnia committed Apr 19, 2020
1 parent caacd9e commit ca0148c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"require": {
"php": ">= 7.1",
"ext-json": "*",
"nesbot/carbon": "^1.26.0 || ^2.0",
"illuminate/contracts": "5.5.* || 5.6.* || 5.7.* || 5.8.* || ^6.0 || ^7.0",
"illuminate/http": "5.5.* || 5.6.* || 5.7.* || 5.8.* || ^6.0 || ^7.0",
"illuminate/pagination": "5.5.* || 5.6.* || 5.7.* || 5.8.* || ^6.0 || ^7.0",
Expand Down
7 changes: 5 additions & 2 deletions src/Subscriptions/StorageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Nuwave\Lighthouse\Subscriptions;

use Carbon\Carbon;
use Illuminate\Cache\CacheManager;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
Expand Down Expand Up @@ -78,7 +79,8 @@ public function storeSubscriber(Subscriber $subscriber, string $topic): void
if ($this->ttl === null) {
$this->cache->forever($channelKey, $subscriber);
} else {
$this->cache->put($channelKey, $subscriber, $this->ttl);
// TODO: Change to just pass the ttl directly when support for Laravel <=5.7 is dropped
$this->cache->put($channelKey, $subscriber, Carbon::now()->addSeconds($this->ttl));
}
}

Expand All @@ -103,7 +105,8 @@ protected function storeTopic(string $key, Collection $topic): void
if ($this->ttl === null) {
$this->cache->forever($key, $topic);
} else {
$this->cache->put($key, $topic, $this->ttl);
// TODO: Change to just pass the ttl directly when support for Laravel <=5.7 is dropped
$this->cache->put($key, $topic, Carbon::now()->addSeconds($this->ttl));
}
}

Expand Down

0 comments on commit ca0148c

Please sign in to comment.