Springcache 框架 -----整合redis ------- 简化它得业务
不使用第三方 redis 数据库产品
默认 使用的是 本地对象进行缓存 ConcurrentHashMap 数据
-
@CachePut注解
* CachePut:将方法返回值放入缓存
* value:缓存的名称,每个缓存名称下面可以有多个key
* key:缓存的key
@CachePut(value = "userCache",key = "#user.id")
2.@CacheEvict注解
* CacheEvict:清理指定缓存
* value:缓存的名称,每个缓存名称下面可以有多个key
* key:缓存的key
@CacheEvict(value = "userCache",key = "#id")
@CacheEvict(value = "userCache",key = "#user.id")
3.@Cacheable注解
* Cacheable:在方法执行前spring先查看缓存中是否有数据,如果有数据,则直接返回缓存数据;若没有数据,调用方法并将方法返回值放到缓存中
* value:缓存的名称,每个缓存名称下面可以有多个key
* key:缓存的key
* condition:条件,满足条件时才缓存数据
* unless:满足条件则不缓存
@Cacheable(value = "userCache",key = "#id",condition = "#result != null")
@Cacheable(value = "userCache",key = "#id",unless = "#result == null")
@Cacheable(value = "userCache",key = "#user.id + '_' + #user.name")