diff --git a/src/LaravelPolicySoftCache.php b/src/LaravelPolicySoftCache.php index 699f731..ab9a96a 100644 --- a/src/LaravelPolicySoftCache.php +++ b/src/LaravelPolicySoftCache.php @@ -97,6 +97,15 @@ protected function callPolicyMethod(Model $user, object $policy, string $ability */ protected function getCacheKey(Model $user, object $policy, array $args, string $ability): string { - return get_class($user).'_'.$user->{$user->getKeyName()}.'_'.hash_hmac('sha512', (string) json_encode($args), config('app.key')).'_'.$ability.'_'.$policy::class; + return collect([ + //the user class + get_class($user), + //the user id + $user->{$user->getKeyName()}, + //hash of the arguments + hash_hmac('sha512', json_encode($args), config('app.key')), + $ability, + get_class($policy), + ])->join('_'); } }