public class BaseCache extends GeneralCacheAdministrator {
private static final long serialVersionUID = 1L;
public void putCache(String key, Object content){
this.putInCache(key, content);
}
public Object getCache(String key){
try {
return this.getFromCache(key,36000);
} catch (NeedsRefreshException e) {
e.printStackTrace();
return null;
}
}
}
public class CacheServiceImpl extends AbstractService implements CacheService {
@Autowired
private BaseCache baseCache;
@Autowired
private ListingService listingService;
//分类加到缓存
@Override
public List getCategoryFromCache(Map params){
String site=params.get("site").toString();
String level=(String)params.get("level");
String cid=(String)params.get("cid");
Object object=null;
boolean isLevel=true;
if(!"".equals(level) && null!=level){
object=baseCache.getCache("category_"+site+"_"+level);
}else{
object=baseCache.getCache("category_"+site+"_"+cid);
isLevel=false;
}
if(object!=null)
return (List) object;
}else{
List categoryList=listingService.getCategoryOne(params);
if(isLevel){
baseCache.putCache("category_"+site+"_"+level, categoryList);
}else{
baseCache.putCache("category_"+site+"_"+cid, categoryList);
}
return categoryList;
}
}