@@ -25,16 +25,22 @@ class CacheTokenRepository extends TokenRepository
25
25
*/
26
26
protected $ cacheTags ;
27
27
28
+ /**
29
+ * @var string
30
+ */
31
+ protected $ cacheStore ;
32
+
28
33
/**
29
34
* @param string $cacheKey
30
35
* @param int $expiresInSeconds
31
36
* @param array $tags
32
37
*/
33
- public function __construct (string $ cacheKey = null , int $ expiresInSeconds = null , array $ tags = [])
38
+ public function __construct (string $ cacheKey = null , int $ expiresInSeconds = null , array $ tags = [], ? string $ store = null )
34
39
{
35
40
$ this ->cacheKey = $ cacheKey ?? 'passport_token_ ' ;
36
41
$ this ->expiresInSeconds = $ expiresInSeconds ?? 5 * 60 ;
37
42
$ this ->cacheTags = $ tags ;
43
+ $ this ->cacheStore = $ store ?? \config ('cache.default ' );
38
44
}
39
45
40
46
/**
@@ -46,7 +52,7 @@ public function __construct(string $cacheKey = null, int $expiresInSeconds = nul
46
52
*/
47
53
public function find ($ id )
48
54
{
49
- return Cache::remember ($ this ->cacheKey . $ id , \now ()->addSeconds ($ this ->expiresInSeconds ), function () use ($ id ) {
55
+ return Cache::store ( $ this -> cacheStore )-> remember ($ this ->cacheKey . $ id , \now ()->addSeconds ($ this ->expiresInSeconds ), function () use ($ id ) {
50
56
return Passport::token ()->where ('id ' , $ id )->first ();
51
57
});
52
58
}
@@ -61,7 +67,7 @@ public function find($id)
61
67
*/
62
68
public function findForUser ($ id , $ userId )
63
69
{
64
- return Cache::remember ($ this ->cacheKey . $ id , \now ()->addSeconds ($ this ->expiresInSeconds ), function () use ($ id , $ userId ) {
70
+ return Cache::store ( $ this -> cacheStore )-> remember ($ this ->cacheKey . $ id , \now ()->addSeconds ($ this ->expiresInSeconds ), function () use ($ id , $ userId ) {
65
71
return Passport::token ()->where ('id ' , $ id )->where ('user_id ' , $ userId )->first ();
66
72
});
67
73
}
@@ -75,7 +81,7 @@ public function findForUser($id, $userId)
75
81
*/
76
82
public function forUser ($ userId ): Collection
77
83
{
78
- return Cache::remember ($ this ->cacheKey . $ userId , \now ()->addSeconds ($ this ->expiresInSeconds ), function () use ($ userId ) {
84
+ return Cache::store ( $ this -> cacheStore )-> remember ($ this ->cacheKey . $ userId , \now ()->addSeconds ($ this ->expiresInSeconds ), function () use ($ userId ) {
79
85
return Passport::token ()->where ('user_id ' , $ userId )->get ();
80
86
});
81
87
}
@@ -90,7 +96,7 @@ public function forUser($userId): Collection
90
96
*/
91
97
public function getValidToken ($ user , $ client )
92
98
{
93
- return Cache::remember ($ this ->cacheKey . $ user ->getKey (), \now ()->addSeconds ($ this ->expiresInSeconds ), function () use ($ client , $ user ) {
99
+ return Cache::store ( $ this -> cacheStore )-> remember ($ this ->cacheKey . $ user ->getKey (), \now ()->addSeconds ($ this ->expiresInSeconds ), function () use ($ client , $ user ) {
94
100
return $ client ->tokens ()
95
101
->whereUserId ($ user ->getKey ())
96
102
->where ('revoked ' , 0 )
0 commit comments