🐛 使用 evictIfPresent 替换 evict,立即删除

1. evict 异步或延迟执行
2. evictIfPresent 立即删除
https://docs.spring.io/spring-framework/docs/6.1.x/javadoc-api/org/springframework/cache/Cache.html
This commit is contained in:
徐晓伟 2023-08-28 16:17:58 +08:00
parent 19be64fdf1
commit f777df58da
2 changed files with 4 additions and 3 deletions

View File

@ -182,8 +182,8 @@ public class PigTokenEndpoint {
if (accessToken == null || StrUtil.isBlank(accessToken.getToken().getTokenValue())) { if (accessToken == null || StrUtil.isBlank(accessToken.getToken().getTokenValue())) {
return R.ok(); return R.ok();
} }
// 清空用户信息 // 清空用户信息立即删除
cacheManager.getCache(CacheConstants.USER_DETAILS).evict(authorization.getPrincipalName()); cacheManager.getCache(CacheConstants.USER_DETAILS).evictIfPresent(authorization.getPrincipalName());
// 清空access token // 清空access token
authorizationService.remove(authorization); authorizationService.remove(authorization);
// 处理自定义退出事件保存相关日志 // 处理自定义退出事件保存相关日志

View File

@ -192,7 +192,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
List<SysUser> userList = baseMapper.selectBatchIds(CollUtil.toList(ids)); List<SysUser> userList = baseMapper.selectBatchIds(CollUtil.toList(ids));
Cache cache = cacheManager.getCache(CacheConstants.USER_DETAILS); Cache cache = cacheManager.getCache(CacheConstants.USER_DETAILS);
for (SysUser sysUser : userList) { for (SysUser sysUser : userList) {
cache.evict(sysUser.getUsername()); // 立即删除
cache.evictIfPresent(sysUser.getUsername());
} }
sysUserRoleMapper.delete(Wrappers.<SysUserRole>lambdaQuery().in(SysUserRole::getUserId, CollUtil.toList(ids))); sysUserRoleMapper.delete(Wrappers.<SysUserRole>lambdaQuery().in(SysUserRole::getUserId, CollUtil.toList(ids)));