[权限扩展] Entrust 缓存问题
以前给Entrust(以下称为权限管理)加上了缓存,当时没怎么细看源码,今天修改权限后发现,新改的权限不怎么好用,查看了源码发现了一些使用问题,在这里记录一下.
首先我们先看一下权限管理
查看缓存源码
trait EntrustUserTrait
{
//Big block of caching functionality.
public function cachedRoles()
{
$userPrimaryKey = $this->primaryKey;
$cacheKey = 'entrust_roles_for_user_'.$this->$userPrimaryKey;
return Cache::tags(Config::get('entrust.role_user_table'))->remember($cacheKey, Config::get('cache.ttl'), function () {
return $this->roles()->get();
});
}
查看去缓存源码
public function save(array $options = [])
{ //both inserts and updates
$result = parent::save($options);
Cache::tags(Config::get('entrust.role_user_table'))->flush();
return $result;
}
public function delete(array $options = [])
{ //soft or hard
$result = parent::delete($options);
Cache::tags(Config::get('entrust.role_user_table'))->flush();
return $result;
}
public function restore()
{ //soft delete undo's
$result = parent::restore();
Cache::tags(Config::get('entrust.role_user_table'))->flush();
return $result;
}
还有trait EntrustRoleTrait 我这里就不一一列出了,总之这些不够我们用,下面我总结了什么时候移除缓存的情况,
① 用户表
当我们修改用户表中的某些字段时,需要清除缓存标签为entrust.role_user_table的标签,比如激活用户.
② 用户角色表
当我们修改用户角色表时,需要清除缓存标签为entrust.role_user_table的标签.
③ 角色表
当我们修改角色表时,需要清除缓存标签为entrust.role_user_table的标签,比如我们修改角色名称时.
④ 角色权限表
当我们修改角色权限表时,需要清除缓存标签为entrust.permission_role_table的标签.
⑤ 权限表
当我们修改权限表时,需要清除缓存标签为entrust.permission_role_table的标签,比如我们修改权限名称时.
希望以上总结能给大家带来帮助!!!
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: