springboot缓存

缓存配置:

@Cacheable注解(缓存添加)
springboot缓存

@CachePut注解:既调用方法,又缓存数据(调用方法之后更新缓存)
springboot缓存
@CacheEvict注解:
springboot缓存

运行流程:

@Cacheable标注的方法执行之前:

  1. 先查询Cache(缓存组件),按照cacheNames指定的名字获取;(CacheManager先获取相应的缓存),第一次获取如果没有Cache组件会自动创建

  2. 去Cache中根据key(默认就是方法的参数)查找缓存

  3. 如果没有查到缓存就调用目标方法

  4. 将目标方法的返回结果,放进缓存中