Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use laravel cache key (to allow multiple apps to use the same caching server) #835

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Entrust/Traits/EntrustRoleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function cachedPermissions()
$rolePrimaryKey = $this->primaryKey;
$cacheKey = 'entrust_permissions_for_role_' . $this->$rolePrimaryKey;
if (Cache::getStore() instanceof TaggableStore) {
return Cache::tags(Config::get('entrust.permission_role_table'))->remember($cacheKey, Config::get('cache.ttl', 60), function () {
return Cache::tags(Config::get('app.key').':'.Config::get('entrust.permission_role_table'))->remember($cacheKey, Config::get('cache.ttl', 60), function () {
return $this->perms()->get();
});
} else return $this->perms()->get();
Expand All @@ -32,7 +32,7 @@ public function save(array $options = [])
return false;
}
if (Cache::getStore() instanceof TaggableStore) {
Cache::tags(Config::get('entrust.permission_role_table'))->flush();
Cache::tags(Config::get('app.key').':'.Config::get('entrust.permission_role_table'))->flush();
}
return true;
}
Expand All @@ -43,7 +43,7 @@ public function delete(array $options = [])
return false;
}
if (Cache::getStore() instanceof TaggableStore) {
Cache::tags(Config::get('entrust.permission_role_table'))->flush();
Cache::tags(Config::get('app.key').':'.Config::get('entrust.permission_role_table'))->flush();
}
return true;
}
Expand All @@ -54,7 +54,7 @@ public function restore()
return false;
}
if (Cache::getStore() instanceof TaggableStore) {
Cache::tags(Config::get('entrust.permission_role_table'))->flush();
Cache::tags(Config::get('app.key').':'.Config::get('entrust.permission_role_table'))->flush();
}
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Entrust/Traits/EntrustUserTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function cachedRoles()
$userPrimaryKey = $this->primaryKey;
$cacheKey = 'entrust_roles_for_user_'.$this->$userPrimaryKey;
if(Cache::getStore() instanceof TaggableStore) {
return Cache::tags(Config::get('entrust.role_user_table'))->remember($cacheKey, Config::get('cache.ttl'), function () {
return Cache::tags(Config::get('app.key').':'.Config::get('entrust.role_user_table'))->remember($cacheKey, Config::get('cache.ttl'), function () {
return $this->roles()->get();
});
}
Expand All @@ -30,22 +30,22 @@ public function cachedRoles()
public function save(array $options = [])
{ //both inserts and updates
if(Cache::getStore() instanceof TaggableStore) {
Cache::tags(Config::get('entrust.role_user_table'))->flush();
Cache::tags(Config::get('app.key').':'.Config::get('entrust.role_user_table'))->flush();
}
return parent::save($options);
}
public function delete(array $options = [])
{ //soft or hard
parent::delete($options);
if(Cache::getStore() instanceof TaggableStore) {
Cache::tags(Config::get('entrust.role_user_table'))->flush();
Cache::tags(Config::get('app.key').':'.Config::get('entrust.role_user_table'))->flush();
}
}
public function restore()
{ //soft delete undo's
parent::restore();
if(Cache::getStore() instanceof TaggableStore) {
Cache::tags(Config::get('entrust.role_user_table'))->flush();
Cache::tags(Config::get('app.key').':'.Config::get('entrust.role_user_table'))->flush();
}
}

Expand Down