.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. Https证书配置

    本文介绍配置免费证书的方法 具体步骤: 一.获取免费CA证书 步骤1到腾讯云找到: 二.申请完成 后域名验证指引 申请域名型证书,可以通过以下方式验证域名的所有权: 1. 手动 DNS 验证 通过解析 ...

  2. Storm实现实时大数据分析(storm介绍,与Hadoop比较,)

    一.storm与Hadoop对比 Hadoop: 全量数据处理使用的大多是鼎鼎大名的hadoop或者hive,作为一个批处理系统,hadoop以其吞吐量大.自动容错等优点,在海量数据处理上得到了广泛的 ...

  3. Linux 常用系统工作命令

    1.echo 用于输出字符串或者变量的值 2.date 显示及设置系统的时间和日期,格式为 “date [选项][+指定格式]”,输入以“+”号开头的参数,及可按照指定格式输出 date命令参数及作用 ...

  4. 【转】【JAVA资料免费下载】158个JAVA免豆精品资料汇总——下载目录

    附件完整版下载地址: http://down.51cto.com/data/431561 附件部分预览~ java中国移动收费系统[源代码] http://down.51cto.com/data/70 ...

  5. part1

    一.hello world 明确的指出 hello.py 脚本由 python 解释器来执行.coding:utf-8处理脚本中的中文 #!/usr/bin/env python # _*_ codi ...

  6. drf框架使用之 路飞学城(第一天)

    1. 路飞学城第一天: 知识点 使用的是序列化与反序列化的使用: 1.创建一个公共相应的Json方法: #创建一个公共响应的类: class LuffyResponse(): def __init__ ...

  7. Java学习前的一些准备

    1.JDK - (Java SE Development Kit) JDK是Java开发所需要的环境,就跟我们想玩某个网游一样,玩之前一定是需要先安装相应的程序包的.那这个JDK就是我们准备登陆Jav ...

  8. 【EFM32】EFM32芯片解锁、加锁操作

    [解锁] 使用J-Flash,新建Project,选择对应的EFM32芯片型号. 选择Target >> Connect >> Unsecure chip ,便进行解锁了,解锁 ...

  9. open()函数 linux中open函数使用

    来源:http://www.cnblogs.com/songfeixiang/p/3733855.html   linux中open函数使用 open函数用来打开一个设备,他返回的是一个整型变量,如果 ...

  10. 文本建模、文本分类相关开源项目推荐(Pytorch实现)

    Awesome-Repositories-for-Text-Modeling repo paper miracleyoo/DPCNN-TextCNN-Pytorch-Inception Deep Py ...