Spring Boot 快速集成 Ehcache 3

Spring Boot 快速集成 Ehcache 3

前言

在互联网服务端架构中,缓存的作用是尤为重要的,无论是基于服务器的内存缓存如 Redis,还是 基于 JVM 的内存缓存如 Ehcache ,在高并发场景中承载着巨大的流量,本文主要针对 JVM 内存框架 Ehcache 3 进行简单地练习,基于Spring Boot 集成 Ehcache 3 搭建一个简单的项目,来实现程序的内存缓存功能支持。

正文

Ehcache 3

Ehcache 是一个开源,具有高性能的 Java 缓存库,由于使用简单,扩展性强,是使用最广泛的 Java 缓存框架,同时具备了内存缓存和磁盘缓存的能力,最新的版本是 Ehcache 3.6。

集成步骤

  1. 首先创建一个基本的 Spring Boot 程序取名为 springboot-ehcache,(版本为 2.1.3,以 maven 作为构建工具,不选择任何依赖。(本项目采用 IDEA 2018.5)

  2. 在项目的 pom.xml 里添加 Ehcache 3 依赖,选择合适的版本,这里采用了3.0.0。

pom.xml

<dependency>
  <groupId>org.ehcache</groupId>
  <artifactId>ehcache</artifactId>
  <version>3.0.0</version>    
 </dependency>
  1. 在项目的 pom.xml 里添加 JSR-107 API 依赖

    关于 JSR-107 API:Java 缓存规范的文档 API,类似 JDBC 规范。

    pom.xml

    <dependency>
        <groupId>javax.cache</groupId>
        <artifactId>cache-api</artifactId>
    </dependency>
    
  2. 添加 Spring Boot 依赖

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-cache</artifactId> 
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId> 
        
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值