【Springboot】Springboot整合Ehcache
刚刚项目上线了,记录下使用的技术......
EhCache 是一个纯Java的进程内缓存框架,具有快速、精干等特点,是Hibernate中默认的CacheProvider。
Ehcache的特点
(1)快速简单,具有多种缓存策略
(2)缓存数据有两级为内存和磁盘,缓存数据会在虚拟机重启的过程中写入磁盘
(3)可以通过RMI、可插入API等方式进行分布式缓存
(4)具有缓存和缓存管理器的侦听接口
(5)支持多缓存管理器实例,以及一个实例的多个缓存区域。并提供Hibernate的缓存实现
项目涉及到的是报文协议转换,使用到各类api或报文格式模版需要缓存至内存中以减少报文转换耗时,选择Ehcache也是比较适合的,快速、简单
话不多说,搭个小demo
一、Springboot整合Ehcache
- 配置依赖
pom.xml中添加ehcache依赖
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
2.配置ehcache.xml
|
<?xml version="1.0" encoding="UTF-8"?> <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" updateCheck="false"> <!-- 磁盘存储:将缓存中暂时不使用的对象,转移到硬盘,类似于Windows系统的虚拟内存 path:指定在硬盘上存储对象的路径 path可以配置的目录有: user.home(用户的家目录) user.dir(用户当前的工作目录) java.io.tmpdir(默认的临时目录) ehcache.disk.store.dir(ehcache的配置目录) 绝对路径(如:d:\\ehcache) 查看路径方法:String tmpDir = System.getProperty("java.io.tmpdir"); --> <diskStore path="java.io.tmpdir" /> <!-- eternal:缓存内容是否永久存储在内存;该值设置为true时,timeToIdleSeconds和timeToLiveSeconds两个属性的值就不起作用了 maxElementsInMemory:设置了缓存的上限,最多存储多少个记录对象 timeToIdleSeconds:缓存创建以后,最后一次访问缓存的日期至失效之时的时间间隔;默认值是0,也就是可闲置时间无穷大 timeToLiveSeconds:缓存自创建日期起至失效时的间隔时间;默认是0.也就是对象存活时间无穷大 overflowToDisk:如果内存中的数据超过maxElementsInMemory,是否使用磁盘存储 diskPersistent:磁盘存储的条目是否永久保存 maxElementsOnDisk:硬盘最大缓存个数 memoryStoreEvictionPolicy:默认策略是 LRU(最近最少使用)。你可以设置为FIFO(先进先出)或是LFU(较少使用) --> <cache name="usercache" eternal="false" maxElementsInMemory="10000" overflowToDisk="true" diskPersistent="false" maxElementsOnDisk="0" timeToIdleSeconds="0" timeToLiveSeconds="0" memoryStoreEvictionPolicy="LRU" /> </ehcache> |
3.配置启用ehcache注解
@SpringBootApplication
@EnableCaching
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
4.
【Springboot】Springboot整合Ehcache的更多相关文章
- springboot 整合ehcache缓存
1.CacheManager Spring Boot默认集成CacheManager,如下包所示: 可以看出springboot自动配置了 JcacheCacheConfiguration. EhCa ...
- 基于SpringBoot从零构建博客网站 - 整合ehcache和开发注册登录功能
对于程序中一些字典信息.配置信息应该在程序启动时加载到缓存中,用时先到缓存中取,如果没有命中,再到数据库中获取同时放到缓存中,这样做可以减轻数据库层的压力.目前暂时先整合ehcache缓存,同时预留了 ...
- SpringBoot 框架整合
代码地址如下:http://www.demodashi.com/demo/12522.html 一.主要思路 使用spring-boot-starter-jdbc集成Mybatis框架 通过sprin ...
- SpringBoot 同时整合thymeleaf html、vue html和jsp
问题描述 SpringBoot如何同时访问html和jsp SpringBoot访问html页面可以,访问jsp页面报错 SpringBoot如何同时整合thymeleaf html.vue html ...
- SpringBoot+AOP整合
SpringBoot+AOP整合 https://blog.csdn.net/lmb55/article/details/82470388 https://www.cnblogs.com/onlyma ...
- SpringBoot+Redis整合
SpringBoot+Redis整合 1.在pom.xml添加Redis依赖 <!--整合Redis--> <dependency> <groupId>org.sp ...
- SpringBoot+Swagger整合API
SpringBoot+Swagger整合API Swagger:整合规范的api,有界面的操作,测试 1.在pom.xml加入swagger依赖 <!--整合Swagger2配置类--> ...
- springboot+maven整合spring security
springboot+maven整合spring security已经做了两次了,然而还是不太熟悉,这里针对后台简单记录一下需要做哪些事情,具体的步骤怎么操作网上都有,不再赘述.1.pom.xml中添 ...
- springboot下整合各种配置文件
本博是在springboot下整合其他中间件,比如,mq,redis,durid,日志...等等 以后遇到再更.springboot真是太便捷了,让我们赶紧涌入到springboot的怀抱吧. ap ...
随机推荐
- C++str.Format
C++应该没有这个函数,说的是Format是在MFC程序里看见的 Format是CString字符串类的成员函数CString::Format( LPCTSTR lpszFormat, ... ); ...
- SOS--DP(基础版本)未压缩空间
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include <cstdio>//sprintf islower isupp ...
- [经验分享] Docker网络解决方案-Weave部署记录
前面说到了Flannel的部署,今天这里说下Docker跨主机容器间网络通信的另一个工具Weave的使用.当容器分布在多个不同的主机上时,这些容器之间的相互通信变得复杂起来.容器在不同主机之间都使用的 ...
- docker-配置网桥-自定义网络
容器网络访问原理 桥接宿主机网络 临时生效: # 网桥名称 br_name=br0 # 添加网桥 brctl addbr $br_name # 给网桥设置IP ip addr add 192.168 ...
- Java 常提到的自然序(Natural Ordering)
Natural Ordering常在容器中被提到,和迭代器一起出现. 在Comparable接口的API规范中找到了描述. (https://docs.oracle.com/javase/8/docs ...
- asp.net 8 Request,Response,Server
Request成员: 1.Request.UrlReferrer 获取请求的来源,可以防盗链 Response.Write(Request.Url.ToString());//获取当前请求的URL地址 ...
- Laravel 查询或写入Enum字段出错的bug解决办法
查询: if($request->filled('type')){ $where[] = ['type', strval(intval($request->input('type')))] ...
- Java 串口通信 Ubuntu
说一下我的操作过程吧 在Windows上先用阿猫串口网络调试助手,进行调试: 在网上找Java代码,我选择的是RXTXcomm,网上代码很多,基本都一样. 在Windows电脑上把rxtx压缩包中的r ...
- ext grid添加2行topbar
bbar: paginToolbar(this.getStore()), dockedItems: [{ xtype: 'toolbar', dock: 'top', items: me.create ...
- Java高并发程序设计学习笔记(十):并发调试和JDK8新特性
转自:https://blog.csdn.net/dataiyangu/article/details/87631574 多线程调试的方法使用Eclipse进行多线程调试线程dump及分析分析死锁案例 ...