参考资料:

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. python web框架 MVC MTV

    WEB框架 MVC Model View Controller 数据库 模板文件 业务处理 MTV Model Template View 数据库 模板文件 业务处理

  2. 如何制作一款HTML5 RPG游戏引擎——第三篇,利用幕布切换场景

    开言: 在RPG游戏中,如果有地图切换的地方,通常就会使用幕布效果.所谓的幕布其实就是将两个矩形合拢,直到把屏幕遮住,然后再展开直到两个矩形全部移出屏幕. 为了大家做游戏方便,于是我给这个引擎加了这么 ...

  3. 项目中遇到的问题, ftp等

    1:ftp 上传文件时的权限问题,需要将上传主目录下的文件权限设置为,这样用户就具有上传,操作,删除等权限 chmod  777 2:  当访问ftp时,出现以下提示.说明需要用户名和密码,这是在ft ...

  4. EventFiringWebDriver网页事件监听(一)

    Selenium提供了很多的event listening functions来跟踪脚本执行过程中的events. How it works? 在注册了listener的webDriver里面,这些l ...

  5. 下载.iso类型的软件如何安装

    法一:这种类型的文件为镜像文件,一般默认在虚拟光驱上运行.通常的做法为: 安装Daemon Tools 虚拟光驱,可以打开CUE.ISO.CCD等这些虚拟光驱的镜像文件,并且将文件虚拟到光盘上使用.运 ...

  6. SecureCRT 7在ubuntu下的破解方法

    主要破解方法: http://www.boll.me/archives/599 http://www.boll.me/archives/680

  7. eclipse 创建jsp报错

  8. 安装vmware虚拟机和linux(centos)

    打开 WMware Workstation 8,然后选择新建虚拟机 2 新建虚拟机向导 选择 自定义(高级)(C)然后点击[下一步]按钮 3 选择虚拟机硬件兼容性 选择 workstation 8.0 ...

  9. hive + hadoop 环境搭建

    机器规划: 主机 ip 进程 hadoop1 10.183.225.158 hive server hadoop2 10.183.225.166 hive client 前置条建: kerberos部 ...

  10. 20145314郑凯杰 《Java程序设计》实验三 敏捷开发与XP实践实验报告

    20145314郑凯杰 <Java程序设计>实验二 实验报告 实验要求 完成实验.撰写实验报告,实验报告以博客方式发表在博客园,注意实验报告重点是运行结果,遇到的问题(工具查找,安装,使用 ...