.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. Disconnected from the target VM, address: '127.0.0.1:57178', transport: 'socket'

    idea 执行测试单元debug时控制台出现:Disconnected from the target VM, address: '127.0.0.1:57178', transport: 'sock ...

  2. LeetCode 147. Insertion Sort List 链表插入排序 C++/Java

    Sort a linked list using insertion sort. A graphical example of insertion sort. The partial sorted l ...

  3. 201772020113李清华《面向对象程序设计(java)》第九周学习总结

    1.实验目的与要求 (1) 掌握java异常处理技术: (2) 了解断言的用法: (3) 了解日志的用途: (4) 掌握程序基础调试技巧: 2.实验内容和步骤 实验1:用命令行与IDE两种环境下编辑调 ...

  4. Docker 多主机方案

    利用OpenVSwitch构建多主机Docker网络 [编者的话]当你在一台主机上成功运行Docker容器后,信心满满地打算将其扩展到多台主机时,却发现前面的尝试只相当于写了个Hello World的 ...

  5. <mvc:resources mapping="/xxx/**" location="/xxx/"/>无效,可能和Controller的URL模式有关

    某项目webapp下有子目录res,其中有img.css.js等存放静态资源的文件夹. 在定义了dispacher-servlet的<url-pattern>/</url-patte ...

  6. K数和问题

    问题描述 给定n个不同的正整数(数组num),整数k(k < = n)以及一个目标数字target.在这n个数里面找出k个数,使得这k个数的和等于目标数字,求问有多少种方案? 解决思路 该类问题 ...

  7. configure,make,make install作用和关系的一些理解

    一. 整体关系 为求直观,画了一张大致关系图: 我个人的理解是这样的,将编译安装比作做菜的话, △ configure的作用,以厨师的构想以参数的形式作为输入,生成并输出菜谱,菜谱包含两个部分---- ...

  8. 将php脚本加入开机启动

    可以看到“/etc/rc.d/init.d”下有很多的文件,每个文件都是可以看到内容的,其实都是一些shell脚本.系统服务的启动就是通过“/etc/rc.d/init.d”中的脚本文件实现的.我们也 ...

  9. Post提交带参网址

    前端 $(function(){ var obj=$('#form1'); obj.validate({ submitHandler: function (form){ var data={}; da ...

  10. 面试必备:ArrayList源码解析(JDK8)

    面试必备:ArrayList源码解析(JDK8) https://blog.csdn.net/zxt0601/article/details/77281231 概述很久没有写博客了,准确的说17年以来 ...