//删除被缓存的对象;
public void remove(String key){
this.flushEntry(this.keyPrefix+"_"+key);
}
//删除所有被缓存的对象;
public void removeAll(Date date){
this.flushAll(date);
}
public void removeAll(){
this.flushAll();
}
//获取被缓存的对象;
public Object get(String key) throws Exception{
try{
return this.getFromCache(this.keyPrefix+"_"+key,this.refreshPeriod);
}
catch (NeedsRefreshException e) {
this.cancelUpdate(this.keyPrefix+"_"+key); throw e;
}
}
}
通过CacheManager类来看怎样缓存对象的,这个类中所用的News只是具体功能的类,我就不贴出来了,你可以自己写一个!
view plainprint?
package com.klstudio;
import com.klstudio.News;
import com.klstudio.cache.BaseCache;
public class CacheManager {
private BaseCache newsCache;
private static CacheManager instance;
private static Object lock = new Object();
public CacheManager() {
//这个根据配置文件来,初始BaseCache而已;
newsCache = new BaseCache("news",1800);
}
public static CacheManager getInstance(){
if (instance == null){
synchronized( lock ){
if (instance == null){
instance = new CacheManager();
}
}
}
return instance;
}