perf:调整授权缓存
This commit is contained in:
@@ -26,7 +26,7 @@ import java.util.stream.Collectors;
|
|||||||
@Component
|
@Component
|
||||||
public class RoleAuthorityAspect {
|
public class RoleAuthorityAspect {
|
||||||
|
|
||||||
public static final String CACHE_HAS_AUTHORITY = "CACHE:HAS_AUTHORITY:{}";
|
public static final String CACHE_HAS_AUTHORITY = "CACHE:HAS_AUTHORITY:{}:{}";
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
TsTokenConfig tsTokenConfig;
|
TsTokenConfig tsTokenConfig;
|
||||||
@@ -53,7 +53,7 @@ public class RoleAuthorityAspect {
|
|||||||
String authority = StrUtil.join("_", classAnnotation.group(),
|
String authority = StrUtil.join("_", classAnnotation.group(),
|
||||||
classAnnotation.value(), annotation.value());
|
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), ";")
|
List<String> authorityList = StrUtil.split(TsCacheService.of().get(cacheKey), ";")
|
||||||
.stream().filter(StrUtil::isNotEmpty).collect(Collectors.toList());
|
.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) {
|
public void onRoleChange(String roleId, String userId) {
|
||||||
if (StrUtil.isNotEmpty(userId)) {
|
TsCacheService.of().keys(StrUtil.format(RoleAuthorityAspect.CACHE_HAS_AUTHORITY,
|
||||||
TsCacheService.of().remove(StrUtil.format(RoleAuthorityAspect.CACHE_HAS_AUTHORITY, userId));
|
roleId, userId)).forEach(key -> TsCacheService.of().remove(key));
|
||||||
} else {
|
|
||||||
TsCacheService.of().keys(StrUtil.replace(RoleAuthorityAspect.CACHE_HAS_AUTHORITY,
|
|
||||||
"{}", "")).forEach(key -> TsCacheService.of().remove(key));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user