缓存技术内部交流_02_Ehcache3 XML 配置
2024-08-27 18:30:57
参考资料:
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 为缓存模板,可以简化配置。
最新文章
- npm源切换
- Create a new Windows service on windows server2012
- iOS开发 适配iOS10以及Xcode8[转]
- PYTHON isinstance语法
- LeetCode&mdash;&mdash;Single Number II(找出数组中只出现一次的数2)
- 读书笔记——body and html
- 教你安装CentOS 6.5如何选择安装包
- Nginx技巧:灵活的server_name,Nginx配置一个服务器多个站点 和 一个站点多个二级域名
- CCF 201403-3	命令行选项 (STL模拟)
- Oracle/PLSQL: Creating Functions
- 如何调整iMindMap打印设置
- C# 扩展方法克隆实体类
- javax.net.ssl.SSLException: java.lang.UnsupportedOperationException
- c# 正则表达式对网页进行内容抓取
- POJ 2250 Compromise (UVA 531)
- TensorFlow问题:The TensorFlow library wasn&#39;t compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
- MSIL实用指南-装箱拆箱
- poj 2253 Frogger (最小最大路段)【dijkstra】
- js 的空值判断程序
- vue render &; array of components &; vue for &; vue-jsx
热门文章
- git别名
- Java集合—Queue(转载)
- oracle RMAN复制数据库
- iOS学习之HelloWorld工程
- flask内置session原理
- 进程 、进程组、会话、控制终端之间的关系 (转载 http://blog.csdn.net/yh1548503342/article/details/41891047)
- android上传图片、视频、文件,服务端使用wcf接收
- JQuery EasyUI 扩展方法 日期控件 设置时间段函数
- 对 META标签 的一点点了解
- Eclipase .自动提示