Skip to content

Commit

Permalink
Wip
Browse files Browse the repository at this point in the history
  • Loading branch information
CaReS0107 committed May 30, 2024
1 parent 92a7687 commit 09ab25e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs-v2/content/en/performance/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ In order to improve performance, Restify caches the policies. You simply have to
],
```

The caching is tight to the current authenticated user so if another user is logged in, the cache will be hydrated for the new user once again.

Restify allows individual caching at the policy level with specific configurations. To enable this, a contract `Cacheable` must be implemneted at the policy level, which enforces the use of the `cache()` method.

``` php
Expand Down
5 changes: 2 additions & 3 deletions src/Cache/PolicyCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ public static function keyForAllowRestify(string $repositoryKey): string
{
$user = app(Request::class)->user();

return "restify.policy.allowRestify.repository-$repositoryKey.user-" . $user?->getKey();
return "restify.policy.allowRestify.repository-$repositoryKey.user-".$user?->getKey();
}

public static function keyForPolicyMethods(string $repositoryKey, string $policyMethod, string|int|null $modelKey): string
{

$modelKey = $modelKey ?? Str::random();

$user = app(Request::class)->user();

return "restify.policy.$policyMethod.repository-$repositoryKey.resource-$modelKey.user-" . $user?->getKey();
return "restify.policy.$policyMethod.repository-$repositoryKey.resource-$modelKey.user-".$user?->getKey();
}

public static function resolve(string $key, callable|Closure $data, Model $model): mixed
Expand Down

0 comments on commit 09ab25e

Please sign in to comment.