参考资料:

http://www.ehcache.org/documentation/3.2/getting-started.html#configuring-with-xml

http://www.ehcache.org/documentation/3.2/xml.html

示例代码:

https://github.com/gordonklg/study,cache module

A. 实例

gordon.study.cache.ehcache3.basic.XmlConfig.java

public class XmlConfig {

    public static void main(String[] args) {
final URL myUrl = XmlConfig.class.getResource("/ehcache3_basic.xml");
Configuration xmlConfig = new XmlConfiguration(myUrl);
CacheManager cacheManager = CacheManagerBuilder.newCacheManager(xmlConfig);
cacheManager.init();
Cache<String, UserModel> phoneUserCache = cacheManager.getCache("phoneUserCache", String.class, UserModel.class);
UserModel user = new UserModel("13316619988", "abc@123.com", "openid12345", "very very long user information ...");
phoneUserCache.put(user.getPhone(), user);
UserModel cached = phoneUserCache.get(user.getPhone());
System.out.println(cached.getInfo());
}
}

示例代码简单明了,没啥好说的。

ehcache3_basic.xml in src/main/resources

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns='http://www.ehcache.org/v3' xmlns:jsr107='http://www.ehcache.org/v3/jsr107'
xsi:schemaLocation="
http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.2.xsd
http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.2.xsd"> <cache-template name="userTemplate">
<key-type>java.lang.String</key-type>
<value-type>gordon.study.cache.ehcache3.basic.UserModel</value-type>
<heap unit="entries">5</heap>
</cache-template> <cache alias="phoneUserCache" uses-template="userTemplate">
<heap unit="entries">20</heap>
</cache> <cache alias="emailUserCache" uses-template="userTemplate" />
</config>

配置文件同样简单明了。其中 cache-template 为缓存模板,可以简化配置。

缓存技术内部交流_02_Ehcache3 XML 配置的更多相关文章

  1. 缓存技术内部交流_05_Cache Through

    参考资料: http://www.ehcache.org/documentation/3.2/caching-patterns.html http://www.ehcache.org/document ...

  2. 缓存技术内部交流_04_Cache Aside续篇

    额外参考资料: http://www.ehcache.org/documentation/3.2/expiry.html F. Cache Aside 模式的问题:缓存过期 有时我们会在上线前给缓存系 ...

  3. 缓存技术内部交流_01_Ehcache3简介

    参考资料: http://www.ehcache.org/documentation/3.2/getting-started.html http://www.ehcache.org/documenta ...

  4. 缓存技术内部交流_03_Cache Aside

    参考资料: http://www.ehcache.org/documentation/3.2/caching-patterns.html http://www.ehcache.org/document ...

  5. ASP.NET Core 缓存技术 及 Nginx 缓存配置

    前言 在Asp.Net Core Nginx部署一文中,主要是讲述的如何利用Nginx来实现应用程序的部署,使用Nginx来部署主要有两大好处,第一是利用Nginx的负载均衡功能,第二是使用Nginx ...

  6. Smarty的配置与高级缓存技术

    转之--http://www.cnblogs.com/-run/archive/2012/06/04/2532801.html Smarty 是一个出色的PHP模板引擎,它分离了逻辑代码和user i ...

  7. .Net环境下的缓存技术介绍 (转)

    .Net环境下的缓存技术介绍 (转) 摘要:介绍缓存的基本概念和常用的缓存技术,给出了各种技术的实现机制的简单介绍和适用范围说明,以及设计缓存方案应该考虑的问题(共17页) 1         概念 ...

  8. .Net环境下的缓存技术介绍

    .Net环境下的缓存技术介绍 摘要: 介绍缓存的基本概念和常用的缓存技术,给出了各种技术的实现机制的简单介绍和适用范围说明,以及设计缓存方案应该考虑的问题(共17页) 1         概念 1.1 ...

  9. ASP.NET 缓存技术分析

    缓存功能是大型网站设计一个很重要的部分.由数据库驱动的Web应用程序,如果需要改善其性能,最好的方法是使用缓存功能.可能的情况下尽量使用缓存,从内存中返回数据的速度始终比去数据库查的速度快,因而可以大 ...

随机推荐

  1. django 模板语言之 simple_tag 自定义模板

    自定义函数 simple_tag a. app项目下创建templatetags目录 b. 创建任意xxoo.py文件 用做自定义py函数 c. 创建template对象 register 在函数或者 ...

  2. 0604-Zuul构建API Gateway-Zuul的回退

    一.概述 参看地址:https://cloud.spring.io/spring-cloud-static/Edgware.SR3/single/spring-cloud.html#hystrix-f ...

  3. 008-Hadoop Hive sql语法详解3-DML 操作:元数据存储

    一.概述 hive不支持用insert语句一条一条的进行插入操作,也不支持update操作.数据是以load的方式加载到建立好的表中.数据一旦导入就不可以修改. DML包括:INSERT插入.UPDA ...

  4. SIP UserAgent (B2BUA client)——pjsip

    SIP UserAgent常用的SIP协议栈有pjsip/bell-sip/sofia-sip/libeXosip/libre等 https://github.com/staskobzar/sip_s ...

  5. 深入理解Flink核心技术(转载)

    作者:李呈祥 Flink项目是大数据处理领域最近冉冉升起的一颗新星,其不同于其他大数据项目的诸多特性吸引了越来越多的人关注Flink项目.本文将深入分析Flink一些关键的技术与特性,希望能够帮助读者 ...

  6. php的soap无故出错的真凶:wsdl缓存

    soap不更新的真凶: 当我修改了服务端的调用方法后,更新了wsdl,客户端的参数老是丢失(不是全丢失,而是部分),让人很郁闷. 第二天我索性增加了一个服务端的新方法,更新了wsdl,但是客户端请求却 ...

  7. Python eval() 的使用:将字符串转换为列表,元祖,字典

    eval() 函数用来执行一个字符串表达式,并返回表达式的值. 语法 以下是 eval() 方法的语法: eval(expression[, globals[, locals]]) 参数 expres ...

  8. linux用户 群组权限

    用户及passwd文件 /etc/passwd文件的功能 /etc/passwd文件每个字段的具体含义 shadow文件 /etc/shadow文件的功能 /etc/shadow文件每个字段的具体含义 ...

  9. centos6.8安装zabbix

    前后用了两台电脑来实验,前后画风不一样,请忽略 一.安装php环境 移除目前系统安装的 PHP 组件 yum remove php* -y 安装 PHP 的 YUM 源  rpm -Uvh http: ...

  10. 20. Valid Parentheses(括号匹配,用桟)

    Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...