ehcache主要是輕量級的緩存實現 ehcache.xml <?xml version="1.0" encoding="UTF-8"?> <ehcache> <diskStore path="G:\\eclipse\\workspace8\\Ehcache\\src\\com\\ij34\\cac ...
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>View Code
簡單測試
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(); } }View Code
結果