设为首页 - 加入收藏 焦点技术网
热搜:java
当前位置:首页 >

ehcache实例

导读:ehCache实例: 4.0.0 com.rx cache 0.0.1-SNAPSHOT net.sf.ehcache ehcache 2.3.1 pom log4j log4j 1.2.14 compile org.slf4j slf4j-log4j12 1.5.6 下面是出来了的xml文件,不要应该也可以。

ehCache实例:


 4.0.0 com.rx cache 0.0.1-SNAPSHOT      net.sf.ehcache   ehcache   2.3.1   pom       log4j   log4j   1.2.14   compile       org.slf4j   slf4j-log4j12   1.5.6   
下面是出来了的xml文件,不要应该也可以。
                        

package com.rx;import java.io.Serializable;import net.sf.ehcache.Cache;import net.sf.ehcache.CacheManager;import net.sf.ehcache.Element;public class EhCache { /**  * @param args  */ public static void main(String[] args) {  System.out.println(1);  // CacheManager manager = new CacheManager();  CacheManager singletonManager = CacheManager.create();  Cache memoryOnlyCache = new Cache("testCache", 5000, false, false, 5, 2);  singletonManager.addCache(memoryOnlyCache);  Cache cache = singletonManager.getCache("testCache");  Element element = new Element("key1", "value1");  cache.put(element);  cache.put(new Element("key1", "value2"));  element = cache.get("key1");  Serializable value = element.getValue();  System.out.println(value);  int elementsInMemory = cache.getSize();  System.out.println(elementsInMemory);  long elementsInMemory2 = cache.getMemoryStoreSize();  System.out.println(elementsInMemory2);  Object obj = element.getObjectValue();  cache.remove("key1");  System.out.println(obj);  singletonManager.shutdown();  // manager.shutdown();  System.out.println(2); }}


(编辑: longronglin)

网友评论