Ehcache入门经典:第一篇
程序员文章站
2022-06-27 19:34:48
ehcache主要是轻量级的缓存实现 ehcache.xml
View Code
View Code
ehcache主要是轻量级的缓存实现
ehcache.xml
<?xml version="1.0" encoding="UTF-8"?> <ehcache> <diskStore path="G:\\eclipse\\workspace8\\Ehcache\\src\\com\\ij34\\cache" /> <defaultCache maxElementsInMemory="100" eternal="true" overflowToDisk="true"/> <cache name="a" maxElementsInMemory="1" eternal="true" overflowToDisk="true" maxElementsOnDisk="0" diskPersistent="true"/> </ehcache>
简单测试
package com.ij34.bean; import net.sf.ehcache.Cache; import net.sf.ehcache.CacheManager; import net.sf.ehcache.Element; public class TestEhcache01 { public static void main(String[] args) { // TODO Auto-generated method stub CacheManager cacheManager=CacheManager.create("./src/com/ij34/source/ehcache.xml"); Cache cache=cacheManager.getCache("a"); Element element=new Element("key1", "我是key1的值"); cache.put(element); System.out.println(cache.get("key1")); System.out.println(cache.get("key1").getValue()); cache.flush(); cacheManager.shutdown(); } }
结果
上一篇: hdu5014---数列异或