From 355557391b101c47219c835c8d789001a80f99df Mon Sep 17 00:00:00 2001 From: Kodeine Date: Sun, 11 Feb 2018 23:57:11 -0600 Subject: [PATCH] Revert "Add tags to the cache to easily purge ACL cache" --- src/Kodeine/Acl/Models/Eloquent/Role.php | 2 +- src/Kodeine/Acl/Traits/HasPermission.php | 16 ++++++---------- src/Kodeine/Acl/Traits/HasRole.php | 4 ++-- src/config/acl.php | 7 ------- 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/Kodeine/Acl/Models/Eloquent/Role.php b/src/Kodeine/Acl/Models/Eloquent/Role.php index 1d6edc4..749c3b3 100644 --- a/src/Kodeine/Acl/Models/Eloquent/Role.php +++ b/src/Kodeine/Acl/Models/Eloquent/Role.php @@ -48,7 +48,7 @@ public function users() */ public function getPermissions() { - return \Cache::tags(config('acl.cacheTags', []))->remember( + return \Cache::remember( 'acl.getPermissionsInheritedById_'.$this->id, config('acl.cacheMinutes'), function () { diff --git a/src/Kodeine/Acl/Traits/HasPermission.php b/src/Kodeine/Acl/Traits/HasPermission.php index 35903f2..c50664f 100644 --- a/src/Kodeine/Acl/Traits/HasPermission.php +++ b/src/Kodeine/Acl/Traits/HasPermission.php @@ -34,8 +34,8 @@ public function permissions() public function getPermissions() { // user permissions overridden from role. - $permissions = \Cache::tags(config('acl.cacheTags', []))->remember( - 'acl.getPermissionsById_' . $this->id, + $permissions = \Cache::remember( + 'acl.getPermissionsById_'.$this->id, config('acl.cacheMinutes'), function () { return $this->getPermissionsInherited(); @@ -48,14 +48,10 @@ function () { // true values. foreach ($this->roles as $role) { foreach ($role->getPermissions() as $slug => $array) { - if (array_key_exists($slug, $permissions)) { + if ( array_key_exists($slug, $permissions) ) { foreach ($array as $clearance => $value) { - if (! array_key_exists($clearance, $permissions[$slug])) { + if( !array_key_exists( $clearance, $permissions[$slug] ) ) { ! $value ?: $permissions[$slug][$clearance] = true; - } else { - if ($permissions[$slug][$clearance] != $value) { - $permissions[$slug][$clearance] = $value; - } } } } else { @@ -78,7 +74,7 @@ public function can($permission, $operator = null) { // user permissions including // all of user role permissions - $merge = \Cache::tags(config('acl.cacheTags', []))->remember( + $merge = \Cache::remember( 'acl.getMergeById_'.$this->id, config('acl.cacheMinutes'), function () { @@ -197,4 +193,4 @@ protected function parsePermissionId($permission) return (int) $permission; } -} +} \ No newline at end of file diff --git a/src/Kodeine/Acl/Traits/HasRole.php b/src/Kodeine/Acl/Traits/HasRole.php index cc58061..e46304b 100644 --- a/src/Kodeine/Acl/Traits/HasRole.php +++ b/src/Kodeine/Acl/Traits/HasRole.php @@ -26,7 +26,7 @@ public function roles() { $model = config('acl.role', 'Kodeine\Acl\Models\Eloquent\Role'); - return $this->belongsToMany($model)->withTimestamps()->orderBy('roles.created_at'); + return $this->belongsToMany($model)->withTimestamps(); } /** @@ -36,7 +36,7 @@ public function roles() */ public function getRoles() { - $this_roles = \Cache::tags(config('acl.cacheTags', []))->remember( + $this_roles = \Cache::remember( 'acl.getRolesById_'.$this->id, config('acl.cacheMinutes'), function () { diff --git a/src/config/acl.php b/src/config/acl.php index e40548f..72c6c1d 100644 --- a/src/config/acl.php +++ b/src/config/acl.php @@ -27,11 +27,4 @@ */ 'cacheMinutes' => 1, - - /** - * Cache tags - * - * All cached entries are tagged to easily purge them on demand - */ - 'cacheTags' => ['acl'] ];