🐛 使用 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-29 08:50:29 +08:00
parent 73a1b2a0ae
commit b3d7221c32
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())) {
return R.ok();
}
// 清空用户信息
cacheManager.getCache(CacheConstants.USER_DETAILS).evict(authorization.getPrincipalName());
// 清空用户信息立即删除
cacheManager.getCache(CacheConstants.USER_DETAILS).evictIfPresent(authorization.getPrincipalName());
// 清空access token
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));
Cache cache = cacheManager.getCache(CacheConstants.USER_DETAILS);
for (SysUser sysUser : userList) {
cache.evict(sysUser.getUsername());
// 立即删除
cache.evictIfPresent(sysUser.getUsername());
}
sysUserRoleMapper.delete(Wrappers.<SysUserRole>lambdaQuery().in(SysUserRole::getUserId, CollUtil.toList(ids)));