perf:调整授权缓存
This commit is contained in:
@@ -26,7 +26,7 @@ import java.util.stream.Collectors;
|
||||
@Component
|
||||
public class RoleAuthorityAspect {
|
||||
|
||||
public static final String CACHE_HAS_AUTHORITY = "CACHE:HAS_AUTHORITY:{}";
|
||||
public static final String CACHE_HAS_AUTHORITY = "CACHE:HAS_AUTHORITY:{}:{}";
|
||||
|
||||
@Resource
|
||||
TsTokenConfig tsTokenConfig;
|
||||
@@ -53,7 +53,7 @@ public class RoleAuthorityAspect {
|
||||
String authority = StrUtil.join("_", classAnnotation.group(),
|
||||
classAnnotation.value(), annotation.value());
|
||||
|
||||
String cacheKey = StrUtil.format(CACHE_HAS_AUTHORITY, tokenBean.getId());
|
||||
String cacheKey = StrUtil.format(CACHE_HAS_AUTHORITY, tokenBean.getRoleId(), tokenBean.getId());
|
||||
List<String> authorityList = StrUtil.split(TsCacheService.of().get(cacheKey), ";")
|
||||
.stream().filter(StrUtil::isNotEmpty).collect(Collectors.toList());
|
||||
|
||||
|
||||
@@ -162,12 +162,8 @@ public class CoreRoleService extends TsServiceBase<CoreRoleGroupMapper, CoreRole
|
||||
* 当授权发生变化时
|
||||
*/
|
||||
public void onRoleChange(String roleId, String userId) {
|
||||
if (StrUtil.isNotEmpty(userId)) {
|
||||
TsCacheService.of().remove(StrUtil.format(RoleAuthorityAspect.CACHE_HAS_AUTHORITY, userId));
|
||||
} else {
|
||||
TsCacheService.of().keys(StrUtil.replace(RoleAuthorityAspect.CACHE_HAS_AUTHORITY,
|
||||
"{}", "")).forEach(key -> TsCacheService.of().remove(key));
|
||||
}
|
||||
TsCacheService.of().keys(StrUtil.format(RoleAuthorityAspect.CACHE_HAS_AUTHORITY,
|
||||
roleId, userId)).forEach(key -> TsCacheService.of().remove(key));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user