Ehcache缓存入门实战(附源码)

Ehcache缓存入门实战(附源码)

Ehcache是一个强大、成熟的Java缓存框架,可以非常容易与其他库和框架集成。官网声称Ehcache可以作为TB级别的数据缓存,并且具有高扩展性。目前Ehcache的最新版本是3.1。

本文不会深究缓存背后的原理,只是作为一个使用Ehcache的例子,由于最近需要做一个类似二级缓存的功能,特地学习了下Ehcache。发现Ehcache作为一个本地缓存框架使用还是非常合适的,但是如果扩展到分布式缓存就需要考虑使用Redis这样的分布式缓存框架了。

为了快速入门,这里使用配置文件的方式整合Ehcache。

创建Maven工程,添加pom.xml依赖如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.rhwayfun</groupId>
    <artifactId>ehcache-demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>ehcache-demo</name>
    <description>ehcache-demo</description>

    <properties>
        <!-- 项目编码 -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <!-- junit版本号 -->
        <junit.version>4.12</junit.version>
        <!-- spring版本号 -->
        <spring.version>3.2.8.RELEASE</spring.version>
    </properties>

    <dependencies>
        <!-- 添加单元测试依赖 -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
        </dependency>

        <!-- 添加Spring依赖 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
           
  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值