栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Spring Boot缓存

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring Boot缓存

文章目录
  • 一、缓存是什么?
  • 二、Simple。
  • 三、Ehcache。
  • 四、Redis。


一、缓存是什么?

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

二、Simple。

导入缓存技术对应的starter


	org.springframework.boot
	spring-boot-starter-cache

启用缓存

@SpringBootApplication
@EnableCaching
public class Springboot19CacheApplication {
	public static void main(String[] args) {
		SpringApplication.run(Springboot19CacheApplication.class, args);
	}
}

设置当前操作的结果数据进入缓存

@Cacheable (value="cacheSpace" ,key="#id")
public Book getById( Integer id) {
	return bookDao.selectById(id);
}
三、Ehcache。

加入Ehcache坐标


	net.sf.ehcache
	ehcache

缓存设定为使用Ehcache

spring:
	cache:
		type: ehcache
		ehcache:
			config: ehcache.xml

提供ehcache配置文件ehcache.xml





四、Redis。

加入redis坐标


	org.springframework.boot
	spring-boot-starter-data-redis

设置redis相关配置

spring:
	redis:
		host: localhost
		port: 6379
	cache :
		type: redis
		redis:
			use-key-prefix: true   #是否使用前缀名(系统定义前缀名)
			key-prefix: sms_   #追加自定义前缀名
			time-to-live: 10s   #有效时长
			cache-null-values: false   #是否允许存储空值
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/946200.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号