1、GeneralCacheAdministrator oscache-2.1.jar
import com.opensymphony.oscache.general.GeneralCacheAdministrator;
private GeneralCacheAdministrator admin = new GeneralCacheAdministrator();
try {
// Get from the cache
preInfo=(LoginInfo)admin.getFromCache(key,myRefreshPeriod);
if(preInfo==null||preInfo.getSubjectAuthority()==null){
preInfo=this.getSysAdminFacade().getLoginAuthoritys(info);
logger.info("read authority data from database");
if(preInfo!=null&&preInfo.getSubjectAuthority()!=null){
admin.putInCache(key, preInfo);
logger.info("put the authortiy into the Cache");
}
}else{
info=preInfo;
}
} catch (NeedsRefreshException nre) {
try {
// Get the value (probably from the database)
preInfo=this.getSysAdminFacade().getLoginAuthoritys(info);
// Store in the cache
admin.putInCache(key, preInfo);
logger.info("refresh the cach data ");
} catch (Exception ex) {
// We have the current content if we want fail-over.
preInfo = (LoginInfo) nre.getCacheContent();
// It is essential that cancelUpdate is called if the
// cached content is not rebuilt
admin.cancelUpdate(key);
logger.info("upate the cach data ");
}
}