NutzCN Logo
问答 springboot redis 缓存使用疑惑
发布于 2479天前 作者 sniperZj 2056 次浏览 复制 上一个帖子 下一个帖子
标签:

@Service
@Transactional
public class TestService {
方法1 @CacheEvict(value = {"getTestById"}, key = "'getTestById'+#test.getId()")
public void updateTest(Test test) {
//....
}
方法二
// @CacheEvict(value = {"getTestById"}, key = "'getTestById'+#test.getId()")
public boolean updateTestInfo(Test test) {
updateTest(test);
return true;
}
//假设外部方法调用 updateTestInfo 时 正常是应该 销毁掉 getTestById 缓存才是 但是 测试发现 并没有
只有再 在 updateTestInfo 申明销毁 才有效 求解 。。。。
}

5 回复

方法返回值的影响吗?

不影响 就是 在 service 里 在建个普通方法去调用 自身需要清空缓存的 方法 清空缓存的操作就没有效果 除非在普通的方法上在加上 清空缓存的操作 才行

@wendal 兽哥啊能 解惑下😆

同一个类,一样的注解,一样的参数,唯一的差别只是返回值,so,无解

@wendal 好像 在 spring boot Application 上注解 @EnableAspectJAutoProxy(proxyTargetClass=true,exposeProxy=true)
然后serverce里调用 换成 ((TestService) AopContext.currentProxy()). updateTest(test) 这种调用方式就行了

添加回复
请先登陆
回到顶部