@@ -25,16 +25,22 @@ class CacheTokenRepository extends TokenRepository
2525 */
2626 protected $ cacheTags ;
2727
28+ /**
29+ * @var string
30+ */
31+ protected $ cacheStore ;
32+
2833 /**
2934 * @param string $cacheKey
3035 * @param int $expiresInSeconds
3136 * @param array $tags
3237 */
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 )
3439 {
3540 $ this ->cacheKey = $ cacheKey ?? 'passport_token_ ' ;
3641 $ this ->expiresInSeconds = $ expiresInSeconds ?? 5 * 60 ;
3742 $ this ->cacheTags = $ tags ;
43+ $ this ->cacheStore = $ store ?? \config ('cache.default ' );
3844 }
3945
4046 /**
@@ -46,7 +52,7 @@ public function __construct(string $cacheKey = null, int $expiresInSeconds = nul
4652 */
4753 public function find ($ id )
4854 {
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 ) {
5056 return Passport::token ()->where ('id ' , $ id )->first ();
5157 });
5258 }
@@ -61,7 +67,7 @@ public function find($id)
6167 */
6268 public function findForUser ($ id , $ userId )
6369 {
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 ) {
6571 return Passport::token ()->where ('id ' , $ id )->where ('user_id ' , $ userId )->first ();
6672 });
6773 }
@@ -75,7 +81,7 @@ public function findForUser($id, $userId)
7581 */
7682 public function forUser ($ userId ): Collection
7783 {
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 ) {
7985 return Passport::token ()->where ('user_id ' , $ userId )->get ();
8086 });
8187 }
@@ -90,7 +96,7 @@ public function forUser($userId): Collection
9096 */
9197 public function getValidToken ($ user , $ client )
9298 {
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 ) {
94100 return $ client ->tokens ()
95101 ->whereUserId ($ user ->getKey ())
96102 ->where ('revoked ' , 0 )
0 commit comments