From 1464e9c4511918a7249db76c25155371daac676d Mon Sep 17 00:00:00 2001 From: George Klincarski Date: Tue, 6 Aug 2024 12:47:53 +0200 Subject: [PATCH] Update RoleDefaultChecker.php Same as with UserDefaultChecker, it avoids pinging the real cache multiple times for the same request. --- src/Checkers/Role/RoleDefaultChecker.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Checkers/Role/RoleDefaultChecker.php b/src/Checkers/Role/RoleDefaultChecker.php index 1f57afb6..29df7a01 100644 --- a/src/Checkers/Role/RoleDefaultChecker.php +++ b/src/Checkers/Role/RoleDefaultChecker.php @@ -64,12 +64,17 @@ public function currentRoleCachedPermissions(): array { $cacheKey = 'laratrust_permissions_for_role_'.$this->role->getKey(); - if (! Config::get('laratrust.cache.enabled')) { - return $this->role->permissions()->get()->toArray(); - } - - return Cache::remember($cacheKey, Config::get('laratrust.cache.expiration_time', 60), function () { - return $this->role->permissions()->get()->toArray(); - }); + return Cache::store('array') + ->rememberForever( + $cacheKey, + function() { + if (! Config::get('laratrust.cache.enabled')) { + return $this->role->permissions()->get()->toArray(); + } + + return Cache::remember($cacheKey, Config::get('laratrust.cache.expiration_time', 60), function () { + return $this->role->permissions()->get()->toArray(); + }); + }); } }