SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第1张图片

目录

1、缓存简介、模拟缓存

2、Spring内置缓存(@EnableCaching、@Cacheable)

3、手机验证码案例

4、Ehcache缓存

6、Redis缓存

7、Memcached缓存

8、jetcache缓存(@EnableCreateCacheAnnotation、@CreateCache) 

9、j2cache(整合任意缓存即一级缓存、二级缓存)

1、缓存简介、模拟缓存

(1)简介:

●缓存是一种介于数据永久存 储介质与数据应用之间的数据临时存储介质
●使用缓存可以有 效的减少低速数据读取过程的次数(例如磁盘I0),提高系统性能
●缓存不仅可以用于提高永久性存储介质的数据读取效率,还可以提供临时的数据存储空间

(2)用HashMap模拟一个缓存

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第2张图片

(3)模拟临时的存储空间

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第3张图片

2、Spring内置缓存(@EnableCaching、@Cacheable)

①导入缓存坐标

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第4张图片

 ②在启动类中加@EnableCaching开启注解

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第5张图片

 ③用@Cacheable注解将输出结果放入缓存,@CachePut为只存不取注解

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第6张图片

3、手机验证码案例

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第7张图片

①控制层(发送手机号获取验证码,检验验证码)

 SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第8张图片

 ②验证码获取工具(随机六位数)

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第9张图片

 ③实现类(此处使用CachePut注解获取不同的验证码,否则key存在他会从缓存中拿之前生成的验证码而不从新生成验证码

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第10张图片

4、Ehcache缓存

①导入相应坐标

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第11张图片

 ②在配置类中修改配置设定缓存使用Ehcache

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第12张图片

 ③提供Ehcache配置文件

默认:

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第13张图片

 起别名(要与注解中的value相对应):

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第14张图片

6、Redis缓存

①导入相应坐标

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第15张图片

 ②更改配置文件,设置Redis相关配置

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第16张图片

 SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第17张图片

7、Memcached缓存

下载与安装:

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第18张图片

 SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第19张图片

 SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第20张图片

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第21张图片

 ①导入相应坐标

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第22张图片

 ②配置memcache服务器属性

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第23张图片

 ③创建读取属性配置信息类,加载配置

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第24张图片

 ④配置客户端配置类

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第25张图片

⑤配置memcached属性

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第26张图片 

 ⑥应用

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第27张图片

8、jetcache缓存(@EnableCreateCacheAnnotation、@CreateCache) 

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第28张图片

 ①导入相应坐标

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第29张图片

 ②配置远程,本地缓存必要属性

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第30张图片SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第31张图片SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第32张图片

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第33张图片 ③开启注解支持(@EnableCreateCacheAnnotation)

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第34张图片

 ④声明缓存对象

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第35张图片

 ⑤操作缓存

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第36张图片

9、j2cache(整合任意缓存即一级缓存、二级缓存)

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第37张图片 

 SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第38张图片SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第39张图片

SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第40张图片 

 SpringBoot整合第三方技术--缓存(内置缓存、Ehcache缓存、Redis缓存、Memcached缓存、jetcache缓存、j2cache)_第41张图片

 

 

你可能感兴趣的:(SpringBoot,缓存,redis,memcached)