jetcache icon indicating copy to clipboard operation
jetcache copied to clipboard

二级缓存@Cached接口和方法上的问题

Open 723854867 opened this issue 4 years ago • 3 comments

@Cached写在接口上必须在实现类上也要写@Cached才可以在redis中找到缓存数据。如果实现类的@Cached去掉就是正常调用。同理如果只写在实现类上,接口上没有注解,必须要用实现类的引用去调用,不能通过接口引用去调用。如何能够只在接口上写注解,通过接口引用调用实现缓存,且具体实现类不用再写注解了

723854867 avatar Aug 22 '20 03:08 723854867

我在看的时候,做过类似的demo,直接在接口上加@Cached注解,通过接口引用去掉,是可以找的到缓存数据的,类似于这样

public interface IUserDao { @Cached(name = "CacheServiceUser", key = "#name", expire = 3600) UserDto getUserDto(String name); }

@Resource
IStudentDao iStudentDao;
iStudentDao.getUserDto("a")

这样是可以获取的,

如果是用下面这种必须在实现接口的地方一块加上@Cached注解才行
@Resource
StudentDaoImpl  studentDaoImpl;
studentDaoImpl.getUserDto("a") ;
测试的版本是2.6,后来在2.5.16依然可以

qinqin111 avatar Sep 01 '20 07:09 qinqin111

问题找到了,是接口使用了 key 属性,需要配置java8的 -parameters 参数才可以生效

723854867 avatar Sep 05 '20 03:09 723854867

我也遇到这个问题,请问你最后是怎么处理的? 你所说的java8的 -parameters 参数要如何设置?

noia-zhou avatar Aug 17 '22 17:08 noia-zhou