ehchahe 例子

package test;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;


public class TestEhCache {

public static void main(String[] args) throws InterruptedException {
CacheManager singletonManager = new CacheManager();
Cache cache = new Cache("00", 1, false, false, 10, 10);
singletonManager.addCache(cache);

cache.put(new Element("1", "1"));
Element el = cache.get("1");
if(el!=null){
System.out.println("1:"+ el.getValue());
}
cache.put(new Element("2", "2"));
el = cache.get("1");
if(el!=null){
System.out.println("1:"+ el.getValue());
}else{
System.out.println("1:null");
}

el = cache.get("2");
if(el!=null){
System.out.println("2:"+ el.getValue());
}

Thread.sleep(10000);

el = cache.get("2");
if(el!=null){
System.out.println("2:"+ el.getValue());
}else{
System.out.println("2:null");
}


}

}

猜你喜欢

转载自aircoder.iteye.com/blog/1774514