@CacheEvict :清除缓存属性
key:指要清除的数据,如 key="#id"
allEntries =true : 指定清除这个缓存中所有数据。
beforeInvocation = true : true在方法之前执行;默认false在方法之后执行,出现异常则不会清除缓存
@CacheConfig 指定缓存公共属性值
@CacheConfig(cacheNames = “user”) 指定在类上,其他方法上就不需要写缓存名。
service中写,案例
@CacheEvict(cacheNames = "user",key = "#id",allEntries = false /*, beforeInvocation = true*/)
public Integer deleteUserById(Integer id){
int i = userMapper.deleteUserById(id);
return i;
}