Commit c434c960a17e1640d2082b657369718ff8dabfc4
Committed by
Gitee
!552 修复MailAccount 更新/删除缓存未清空
Merge pull request !552 from ZJY/fix_redisCache
Showing
1 changed file
with
5 additions
and
2 deletions
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountServiceImpl.java
| ... | ... | @@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; |
| 9 | 9 | import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; |
| 10 | 10 | import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants; |
| 11 | 11 | import lombok.extern.slf4j.Slf4j; |
| 12 | +import org.springframework.cache.annotation.CacheEvict; | |
| 12 | 13 | import org.springframework.cache.annotation.Cacheable; |
| 13 | 14 | import org.springframework.stereotype.Service; |
| 14 | 15 | import org.springframework.validation.annotation.Validated; |
| ... | ... | @@ -46,7 +47,8 @@ public class MailAccountServiceImpl implements MailAccountService { |
| 46 | 47 | } |
| 47 | 48 | |
| 48 | 49 | @Override |
| 49 | - @Cacheable(value = RedisKeyConstants.MAIL_ACCOUNT, key = "#updateReqVO.id") | |
| 50 | + @CacheEvict(value = RedisKeyConstants.MAIL_ACCOUNT, | |
| 51 | + allEntries = true)// allEntries 清空所有缓存,主要一次更新涉及到的 mailAccountId 较多,反倒批量会更快 | |
| 50 | 52 | public void updateMailAccount(MailAccountUpdateReqVO updateReqVO) { |
| 51 | 53 | // 校验是否存在 |
| 52 | 54 | validateMailAccountExists(updateReqVO.getId()); |
| ... | ... | @@ -57,7 +59,8 @@ public class MailAccountServiceImpl implements MailAccountService { |
| 57 | 59 | } |
| 58 | 60 | |
| 59 | 61 | @Override |
| 60 | - @Cacheable(value = RedisKeyConstants.MAIL_ACCOUNT, key = "#id") | |
| 62 | + @CacheEvict(value = RedisKeyConstants.MAIL_ACCOUNT, | |
| 63 | + allEntries = true) // allEntries 清空所有缓存,主要一次更新涉及到的 mailAccountId 较多,反倒批量会更快 | |
| 61 | 64 | public void deleteMailAccount(Long id) { |
| 62 | 65 | // 校验是否存在账号 |
| 63 | 66 | validateMailAccountExists(id); | ... | ... |