其他分享
首页 > 其他分享> > spring对缓存的使用@Cacheable

spring对缓存的使用@Cacheable

作者:互联网

@Cacheable(value = "CACHE_BOOK",key = "#username", condition = "#language = 1")
public List<Book> getBooksByUsernameAndLanguage(String username, int language) {
     // balabalabala...里面的代码不重要
     return bookList;
}

@Cacheable注解只有三个属性。

 

 

 

 注意事项:1、@Cacheable必须开启缓存在启动类上@EnableCaching

      2、返回的对象要实现缓存该对象是必须实现序列化接口的Serializable

      3、@Cacheable不可用在私有方法上面,可以放在接口和具体的方法上面

      4、@Cacheable这个注解是放在具体的方法上;

      5、@CacheConfig这个注解只能放在类上代表这个类所有缓存的公共属性配置,比如value等非必须;

      6、key = "#对象.属性"或者直接使用key = "#属性";直接读取的是方法形参内的参数属性或者对象;

     7、key = "#对象.属性.concat('Hydrologydata')"

  

标签:username,Cacheable,spring,缓存,bookList,key,属性
来源: https://www.cnblogs.com/wwwcf1982603555/p/14593270.html