mirror of https://github.com/elunez/eladmin
[代码优化](v2.6): 完善CacheKey中的变量命名以及调用 (#568)
* correct variable name of String DATA_USER in CacheKey.java * complete other CacheKey name * add job CacheKeypull/572/head
parent
9e6c5d6d96
commit
9fc0524901
|
@ -29,10 +29,11 @@ public interface CacheKey {
|
|||
/**
|
||||
* 数据
|
||||
*/
|
||||
String DATE_USER = "data::user:";
|
||||
String DATA_USER = "data::user:";
|
||||
/**
|
||||
* 菜单
|
||||
*/
|
||||
String MENU_ID = "menu::id:";
|
||||
String MENU_USER = "menu::user:";
|
||||
/**
|
||||
* 角色授权
|
||||
|
@ -42,4 +43,16 @@ public interface CacheKey {
|
|||
* 角色信息
|
||||
*/
|
||||
String ROLE_ID = "role::id:";
|
||||
/**
|
||||
* 部门
|
||||
*/
|
||||
String DEPT_ID = "dept::id:";
|
||||
/**
|
||||
* 岗位
|
||||
*/
|
||||
String JOB_ID = "job::id:";
|
||||
/**
|
||||
* 数据字典
|
||||
*/
|
||||
String DICT_NAME = "dict::name:";
|
||||
}
|
||||
|
|
|
@ -275,7 +275,7 @@ public class DeptServiceImpl implements DeptService {
|
|||
public void delCaches(Long id){
|
||||
List<User> users = userRepository.findByDeptRoleId(id);
|
||||
// 删除数据权限
|
||||
redisUtils.delByKeys("data::user:",users.stream().map(User::getId).collect(Collectors.toSet()));
|
||||
redisUtils.del("dept::id:" + id);
|
||||
redisUtils.delByKeys(CacheKey.DATA_USER, users.stream().map(User::getId).collect(Collectors.toSet()));
|
||||
redisUtils.del(CacheKey.DEPT_ID + id);
|
||||
}
|
||||
}
|
|
@ -20,10 +20,7 @@ import me.zhengjie.modules.system.domain.Dict;
|
|||
import me.zhengjie.modules.system.domain.DictDetail;
|
||||
import me.zhengjie.modules.system.repository.DictRepository;
|
||||
import me.zhengjie.modules.system.service.dto.DictDetailQueryCriteria;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
import me.zhengjie.utils.QueryHelp;
|
||||
import me.zhengjie.utils.RedisUtils;
|
||||
import me.zhengjie.utils.ValidationUtil;
|
||||
import me.zhengjie.utils.*;
|
||||
import me.zhengjie.modules.system.repository.DictDetailRepository;
|
||||
import me.zhengjie.modules.system.service.DictDetailService;
|
||||
import me.zhengjie.modules.system.service.dto.DictDetailDto;
|
||||
|
@ -93,6 +90,6 @@ public class DictDetailServiceImpl implements DictDetailService {
|
|||
|
||||
public void delCaches(DictDetail dictDetail){
|
||||
Dict dict = dictRepository.findById(dictDetail.getDict().getId()).orElseGet(Dict::new);
|
||||
redisUtils.del("dict::name:" + dict.getName());
|
||||
redisUtils.del(CacheKey.DICT_NAME + dict.getName());
|
||||
}
|
||||
}
|
|
@ -115,6 +115,6 @@ public class DictServiceImpl implements DictService {
|
|||
}
|
||||
|
||||
public void delCaches(Dict dict){
|
||||
redisUtils.del("dict::name:" + dict.getName());
|
||||
redisUtils.del(CacheKey.DICT_NAME + dict.getName());
|
||||
}
|
||||
}
|
|
@ -100,7 +100,7 @@ public class JobServiceImpl implements JobService {
|
|||
public void delete(Set<Long> ids) {
|
||||
jobRepository.deleteAllByIdIn(ids);
|
||||
// 删除缓存
|
||||
redisUtils.delByKeys("job::id:", ids);
|
||||
redisUtils.delByKeys(CacheKey.JOB_ID, ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -344,12 +344,12 @@ public class MenuServiceImpl implements MenuService {
|
|||
*/
|
||||
public void delCaches(Long id){
|
||||
List<User> users = userRepository.findByMenuId(id);
|
||||
redisUtils.del("menu::id:" +id);
|
||||
redisUtils.delByKeys("menu::user:",users.stream().map(User::getId).collect(Collectors.toSet()));
|
||||
redisUtils.del(CacheKey.MENU_ID + id);
|
||||
redisUtils.delByKeys(CacheKey.MENU_USER, users.stream().map(User::getId).collect(Collectors.toSet()));
|
||||
// 清除 Role 缓存
|
||||
List<Role> roles = roleService.findInMenuId(new ArrayList<Long>(){{
|
||||
add(id);
|
||||
}});
|
||||
redisUtils.delByKeys("role::id:",roles.stream().map(Role::getId).collect(Collectors.toSet()));
|
||||
redisUtils.delByKeys(CacheKey.ROLE_ID, roles.stream().map(Role::getId).collect(Collectors.toSet()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -217,7 +217,7 @@ public class RoleServiceImpl implements RoleService {
|
|||
if (CollectionUtil.isNotEmpty(users)) {
|
||||
users.forEach(item -> userCacheClean.cleanUserCache(item.getUsername()));
|
||||
Set<Long> userIds = users.stream().map(User::getId).collect(Collectors.toSet());
|
||||
redisUtils.delByKeys(CacheKey.DATE_USER, userIds);
|
||||
redisUtils.delByKeys(CacheKey.DATA_USER, userIds);
|
||||
redisUtils.delByKeys(CacheKey.MENU_USER, userIds);
|
||||
redisUtils.delByKeys(CacheKey.ROLE_AUTH, userIds);
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ public class UserServiceImpl implements UserService {
|
|||
}
|
||||
// 如果用户的角色改变
|
||||
if (!resources.getRoles().equals(user.getRoles())) {
|
||||
redisUtils.del(CacheKey.DATE_USER + resources.getId());
|
||||
redisUtils.del(CacheKey.DATA_USER + resources.getId());
|
||||
redisUtils.del(CacheKey.MENU_USER + resources.getId());
|
||||
redisUtils.del(CacheKey.ROLE_AUTH + resources.getId());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue