Skip to content

Commit c2a8d3a

Browse files
committed
Check taggable store #7.
1 parent 60ff01a commit c2a8d3a

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/CacheTokenRepository.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Overtrue\LaravelPassportCacheToken;
44

5+
use Illuminate\Cache\TaggableStore;
6+
use Illuminate\Contracts\Cache\Repository;
57
use Illuminate\Database\Eloquent\Collection;
68
use Laravel\Passport\Passport;
79
use Laravel\Passport\Token;
@@ -53,7 +55,7 @@ public function __construct(string $cacheKeyPrefix = null, int $expiresInSeconds
5355
*/
5456
public function find($id)
5557
{
56-
return Cache::store($this->cacheStore)->tags($this->cacheTags)->remember(
58+
return $this->store()->remember(
5759
$this->itemKey($id),
5860
\now()->addSeconds($this->expiresInSeconds),
5961
function () use ($id) {
@@ -72,7 +74,7 @@ function () use ($id) {
7274
*/
7375
public function findForUser($id, $userId)
7476
{
75-
return Cache::store($this->cacheStore)->tags($this->cacheTags)->remember(
77+
return $this->store()->remember(
7678
$this->itemKey($id),
7779
\now()->addSeconds($this->expiresInSeconds),
7880
function () use ($id, $userId) {
@@ -90,7 +92,7 @@ function () use ($id, $userId) {
9092
*/
9193
public function forUser($userId): Collection
9294
{
93-
return Cache::store($this->cacheStore)->tags($this->cacheTags)->remember(
95+
return $this->store()->remember(
9496
$this->itemKey($userId),
9597
\now()->addSeconds($this->expiresInSeconds),
9698
function () use ($userId) {
@@ -109,7 +111,7 @@ function () use ($userId) {
109111
*/
110112
public function getValidToken($user, $client)
111113
{
112-
return Cache::store($this->cacheStore)->tags($this->cacheTags)->remember(
114+
return $this->store()->remember(
113115
$this->itemKey($user->getKey()),
114116
\now()->addSeconds($this->expiresInSeconds),
115117
function () use ($client, $user) {
@@ -126,4 +128,11 @@ public function itemKey(string $key)
126128
{
127129
return $this->cacheKeyPrefix . $key;
128130
}
131+
132+
public function store(): Repository
133+
{
134+
$store = Cache::store($this->cacheStore);
135+
136+
return $store instanceof TaggableStore ? $store->tags($this->cacheTags) : $store;
137+
}
129138
}

0 commit comments

Comments
 (0)