From d3088e3ae2d6e99ae213ff8661fa0396c4e44c50 Mon Sep 17 00:00:00 2001 From: Lupacescu Eduard Date: Sun, 31 Jul 2022 00:11:23 +0300 Subject: [PATCH] fix: fixing cache enable option (#498) --- src/Cache/PolicyCache.php | 4 ++++ src/Traits/AuthorizableModels.php | 8 +------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Cache/PolicyCache.php b/src/Cache/PolicyCache.php index d41bf67a..53fde5e4 100644 --- a/src/Cache/PolicyCache.php +++ b/src/Cache/PolicyCache.php @@ -32,6 +32,10 @@ public static function keyForPolicyMethods(string $repositoryKey, string $policy public static function resolve(string $key, callable|Closure $data): mixed { + if (! static::enabled()) { + return $data(); + } + if (Cache::has($key)) { return Cache::get($key); } diff --git a/src/Traits/AuthorizableModels.php b/src/Traits/AuthorizableModels.php index dcbae8db..d55b4842 100644 --- a/src/Traits/AuthorizableModels.php +++ b/src/Traits/AuthorizableModels.php @@ -35,13 +35,7 @@ public static function authorizedToUseRepository(Request $request): bool : false; }; - if (! PolicyCache::enabled()) { - return $resolver(); - } - - $key = PolicyCache::keyForAllowRestify(static::uriKey()); - - return PolicyCache::resolve($key, $resolver); + return PolicyCache::resolve(PolicyCache::keyForAllowRestify(static::uriKey()), $resolver); } /**