SpringBoot提供的缓存技术除了提供默认的缓存方案,还可以对其他缓存技术进行整合,统一接口,方便缓存技术的开发与管理
这里使用的是springboot内置的simple缓存
使用步骤
1.启用缓存
2.设置进入缓存的数据
3.设置读取缓存的数据
启用缓存
在引导类上添加@EnableCaching注解,代表springboot开启了缓存功能
@SpringBootApplication(scanBasePackages = {"com.nf.springboot"})
@EnableCaching//开启缓存功能
public class CacheApplication {
public static void main(String[] args) {
SpringApplication.run(CacheApplication.class, args);
}
}
设置进入缓存的数据
在方法上添加@CachePut注解,用于缓存数据,该注解无法获取缓存中的数据,只用于缓存数据.
方法的返回值则是需要进行缓存的数据
数据指向:smsCode(缓存名称)-->tel(键值)-->return(方法返回的数据)