.Ehcache简单说明及使用

EhCache 是一个纯Java的进程内缓存框架,具有快速、精干等特点,是Hibernate中默认的CacheProvider。
Ehcache是一种广泛使用的开源Java分布式缓存。主要面向通用缓存,Java EE和轻量级容器。它具有内存和磁盘存储,缓存加载器,缓存扩展,缓存异常处理程序,一个gzip缓存servlet过滤器,支持REST和SOAP api等特点。
Ehcache最初是由Greg Luck于2003年开始开发。2009年,该项目被Terracotta购买。软件仍然是开源,但一些新的主要功能(例如,快速可重启性之间的一致性 的)只能在商业产品中使用,例如Enterprise EHCache and BigMemory。,维基媒体Foundationannounced目前使用的就是Ehcache技术。 Ehcache2.6.6 源码和jar包下载地址:https://oss.sonatype.org/content/repositories/sourceforge-releases/net/sf/ehcache/ehcache-core/2.6.6/ 2.1 添加依赖
```xml
<!-- 缓存 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<!-- ehcache -->
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
``` 2.2 加入注解 @EnableCaching
```java
@SpringBootApplication
@EntityScan(basePackages ={ "entity","com.holworth.domain"})
@EnableCaching
public class domainApplication {}
```
2.3 EhCache配置
在src\main\resources目录下,添加ehcache.xml文件,
```xml
<?xml version="1.0" encoding="UTF-8" ?>
<ehcache>
<cache name="objectCache" maxElementsInMemory=""></cache>
</ehcache>
```
2.4 application.application配置
# 配置ehcache缓存
spring.cache.type=ehcache
# 指定ehcache配置文件路径
spring.cache.ehcache.config=classpath:/ehcache.xml 2.5
```java
package com.holworth.domain; import entity.BasCurrency;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.cache.Cache;
import org.springframework.cache.annotation.EnableCaching;
import util.HraUtility;
import org.springframework.cache.CacheManager; import javax.annotation.Resource;
import java.util.List; @SpringBootApplication
@EntityScan(basePackages ={ "entity","com.holworth.domain"})
@EnableCaching
public class domainApplication {
@Resource
private CacheManager cacheManager;
// @Autowired
// private static com.holworth.domain.dao.a commonService; public static void main(String[] args) {
//http://localhost:8086/MKT/MktRiskPriceManage.html
//http://localhost:8080/api/RiskFactor/GetRiskFactor
SpringApplication.run(domainApplication.class);
CacheManager cacheManager = (CacheManager) SpringContextUtils.getBean("CacheManager");
Cache cache = cacheManager.getCache("objectCache");
cache.put("key", "");
System.out.println("缓存成功");
String res = cache.get("key", String.class);
System.out.println(res);
}
}
```

springboot Ehcache使用的更多相关文章

  1. springboot + ehcache

    一.使用 springboot + ehcache本地堆缓存实现相应功能 1.引入ehcache的jar包 2.创建ehcache的xml配置文件 <?xml version="1.0 ...

  2. spring-boot + Ehcache without XML

    http://stackoverflow.com/questions/21944202/using-ehcache-in-spring-4-without-xml 1.Ehcache配置类 @Conf ...

  3. springboot Ehcache缓存配置

    例牌的导包 <!-- 包含支持UI模版(Velocity,FreeMarker,JasperReports), 邮件服务, 脚本服务(JRuby), 缓存Cache(EHCache), 任务计划 ...

  4. springboot+ehcache 基于注解实现简单缓存demo

    1.加入maven依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactI ...

  5. springboot(十九):SpringBoot+EHcache实现缓存

    https://blog.csdn.net/qq_28143647/article/details/79789368

  6. spring boot学习(十三)SpringBoot缓存(EhCache 2.x 篇)

    SpringBoot 缓存(EhCache 2.x 篇) SpringBoot 缓存 在 Spring Boot中,通过@EnableCaching注解自动化配置合适的缓存管理器(CacheManag ...

  7. Spring Boot集成EHCache实现缓存机制

    SpringBoot 缓存(EhCache 2.x 篇) SpringBoot 缓存 在 Spring Boot中,通过@EnableCaching注解自动化配置合适的缓存管理器(CacheManag ...

  8. springboot+mybatis+ehcache实现缓存数据

    一.springboot缓存简介 在 Spring Boot中,通过@EnableCaching注解自动化配置合适的缓存管理器(CacheManager),Spring Boot根据下面的顺序去侦测缓 ...

  9. SpringBoot整合Shiro使用Ehcache等缓存无效问题

    前言 整合有缓存.事务的spring boot项目一切正常. 在该项目上整合shiro安全框架,发现部分类的缓存Cache不能正常使用. 然后发现该类的注解基本失效,包括事务Transaction注解 ...

随机推荐

  1. Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class

    Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdb ...

  2. vChart

    vue+echarts工具:    https://v-charts.js.org

  3. Python创建随机用户名密码并存放于Access数据库

    利用random库随机生成4到32位包含字母跟数字的用户名密码,利用win32com库连接到access数据库并写入table,要更改创建的用户名密码数量修改18行代码的数字即可. import wi ...

  4. Python来袭,教你用Neo4j构建“复联4”人物关系图谱!

    来源商业新知网,原标题:Python来袭,教你用Neo4j构建“复联4”人物关系图谱!没有剧透! 复仇者联盟 之绝对不剧透 漫威英雄们为了不让自己剧透也是使出了浑身解数.在洛杉矶全球首映礼上记者费尽心 ...

  5. ARTS打卡计划第一周-Tips-ControllerAdvice的使用

    通常在开发具体项目过程中我们可能会面临如下问题: 统一所有的json返回结果 统一处理所有controller中的异常,并且给不同异常不同的返回状态值 统一对返回的接口做数据校验或者加密,防止篡改 在 ...

  6. 在类文件中创建 写入Json文件

    由于业务需要 今天写了一个方法能够定时更新Json文件 即定时从数据库中查询数据 然后转化为Json对象 如果有数据的话 删掉之前的Json文件 重新创建一个文件 然后写入Json对象 中间走了很多弯 ...

  7. C# File API

    [C# File API] 1.System.IO.File Provides static methods for the creation, copying, deletion, moving, ...

  8. OpenTSDB/HBase的调优过程整理

    背景 过年前,寂寞哥给我三台机器,说搞个新的openTSDB集群.机器硬件是8核16G内存.3个146G磁盘做数据盘. 我说这太抠了,寂寞哥说之前的TSDB集群运行了两年,4台同样配置的机器,目前hd ...

  9. Python Selenium系列学习

    以下记录刚接触Python Selenium操作Web UI的学习问题: 1.python selenium三种等待方式: ①强制等待:time.sleep(value):设置等待最简单的方法就是强制 ...

  10. max_delay/min_delay和input_delay/output_delay

    今天在使用DC设置随路时钟的时候发现里两个比较容易混淆的设置:max_delay/min_delay和input_delay/output_delay. 1)max_delay/min_delay设置 ...