spring cache 提供了缓存的一些注解:
1、@Cacheable
(1)condition属性:可以为spEL表达式,只要满足表达式时才进行缓存。
(2)unless属性:和condition不同的是,在方法执行之后才对条件进行判断,满足条件才进行缓存。所以unless可以对result做判断。示例:只有result为true时才进行缓存
@Cacheable(value = "aa", key = "#param", unless = "#result")
public boolean isTrue(String param) {
if (param.equals("aaa")) {
return true;
}
else {
return false;
}
}
@Cacheable注解不生效原因
2、@CachePut
3、@CacheEvict
在注解上增加缓存生效时间
spring cacheable和redis集成
1、配置CacheManager
1、配置redis集群
需要注意:
方法A在同一个类中调用带注解的方法B,注解不能生效
spring cache + 服务器缓存(encache)
1、配置ehcache.xml文件
spring cache
原文:https://www.cnblogs.com/BonnieWss/p/11607455.html