EhCache 集成

EhCache 是一个纯 Java 的进程内缓存框架,具有快速、精干等特点,是 Hibernate 中默认的 CacheProvider。

在 Spring Boot 中集成 EhCache 非常容易,只需要两个步骤。

首先,在 pom.xml 中增加 EhCache 依赖。

<dependency>
  <groupId>net.sf.ehcache</groupId>
  <artifactId>ehcache</artifactId>
</dependency>

第二步,在 src/main/resources 目录下创建 ehcache.xml。

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd">
  <cache name="ehcache" maxElementsInMemory="1000" timeToLiveSeconds="300"></cache>
</ehcache

其中,maxElementsInMemory,表示缓存最大数目。 timeToLiveSeconds: ,表示设置对象在失效前允许存活时间(单位:秒)。

如果想对 ehcache.xml 更深入的了解,可以参考 http://www.ehcache.org/ehcache.xml。

运行起来,控制台打印的日志信息,说明已经是EhCacheManager实例,说明 EhCache 开启成功了。

  1. Bean 'cacheManager' of type [class org.springframework.cache.ehcache.EhCacheCacheManager]

最新文章

  1. Quartz 在 Spring 中如何动态配置时间--转
  2. Linux CentOS6.8下解压安装mysql-5.7.14完整介绍
  3. java实验2实验报告(20135131)
  4. ABAP-SQL基础知识
  5. python文件选择:tkFileDialog 基础
  6. [Ubuntu] 转载-使用Ubuntu修复grub
  7. 51nod 数数字(水题)
  8. cf468A 24 Game
  9. Asp.Net Web API 2(CRUD操作)第二课
  10. JavaScript 跨域方法总结
  11. seo从业者发展方向
  12. Vue2学习(2)
  13. MongoDB之常用操作
  14. L2-002 链表去重 (25 分)
  15. 模板引擎,中间件,spring AOP原理
  16. 【repost】javascript callback
  17. 性能测试八:jmeter进阶之beanshell
  18. csrf漏洞
  19. Linux文件管理常用命令用法总结
  20. python selenium-webdriver 标签页切换(十五)

热门文章

  1. Spring源码解析——核心类介绍
  2. SQL列转行,行转列实现
  3. Python模块04/包/logging日志
  4. 基于animate.css动画库的全屏滚动小插件,适用于vue.js(移动端、pc)项目
  5. md5加密密码
  6. 使用MapReduce运行WordCount案例
  7. 上亿数据怎么玩深度分页?兼容MySQL + ES + MongoDB
  8. DEX文件解析--4、dex类的类型解析
  9. Java 线程与同步的性能优化
  10. 分布式ID生成服务,真的有必要搞一个