diff --git a/src/Checkers/Role/RoleDefaultChecker.php b/src/Checkers/Role/RoleDefaultChecker.php index 1f57afb6..63016a42 100644 --- a/src/Checkers/Role/RoleDefaultChecker.php +++ b/src/Checkers/Role/RoleDefaultChecker.php @@ -64,12 +64,16 @@ 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::store('array')->rememberForever( + $cacheKey, + function () use ($cacheKey) { + 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::remember($cacheKey, Config::get('laratrust.cache.expiration_time', 60), function () { + return $this->role->permissions()->get()->toArray(); + }); + }); } } diff --git a/src/Checkers/User/UserDefaultChecker.php b/src/Checkers/User/UserDefaultChecker.php index 28c94106..de43e791 100644 --- a/src/Checkers/User/UserDefaultChecker.php +++ b/src/Checkers/User/UserDefaultChecker.php @@ -152,13 +152,17 @@ protected function userCachedRoles(): array { $cacheKey = 'laratrust_roles_for_'.$this->userModelCacheKey().'_'.$this->user->getKey(); - if (! Config::get('laratrust.cache.enabled')) { - return $this->user->roles()->get()->toArray(); - } + return Cache::store('array')->rememberForever( + $cacheKey, + function () use ($cacheKey) { + if (! Config::get('laratrust.cache.enabled')) { + return $this->user->roles()->get()->toArray(); + } - return Cache::remember($cacheKey, Config::get('laratrust.cache.expiration_time', 60), function () { - return $this->user->roles()->get()->toArray(); - }); + return Cache::remember($cacheKey, Config::get('laratrust.cache.expiration_time', 60), function () { + return $this->user->roles()->get()->toArray(); + }); + }); } /** @@ -170,13 +174,17 @@ public function userCachedPermissions(): array { $cacheKey = 'laratrust_permissions_for_'.$this->userModelCacheKey().'_'.$this->user->getKey(); - if (! Config::get('laratrust.cache.enabled')) { - return $this->user->permissions()->get()->toArray(); - } + return Cache::store('array')->rememberForever( + $cacheKey, + function () use ($cacheKey) { + if (! Config::get('laratrust.cache.enabled')) { + return $this->user->permissions()->get()->toArray(); + } - return Cache::remember($cacheKey, Config::get('laratrust.cache.expiration_time', 60), function () { - return $this->user->permissions()->get()->toArray(); - }); + return Cache::remember($cacheKey, Config::get('laratrust.cache.expiration_time', 60), function () { + return $this->user->permissions()->get()->toArray(); + }); + }); } /**