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");
}


}

}

你可能感兴趣的:(cache)