portal html css js resource

cacheUtil.js 1.9KB

    (function(window) { var objCache={"professor":{},"company":{}}; var objHCache={"professor":{},"company":{}};//队列(processing) var objCacheHandler={ "professor":function(id){ jQuery.ajax({ url:"/ajax/professor/baseInfo/"+id, type:"GET", success:function(res){ var ha = objHCache.professor[id];//jilu delete objHCache.professor[id]; if(res.success){ objCache.professor[id]=res.data; for(var i = 0 ;i < ha.length;++i){ ha[i](true,res.data); } }else{ for(var i = 0 ;i < ha.length;++i){ ha[i](false); } } }, error:function(dfd){ ha[i](false); } }) }, "company":function(id){ jQuery.ajax({ url:"/ajax/org/"+id, type:"GET", success:function(res){ var ha = objHCache.company[id];//jilu delete objHCache.company[id]; if(res.success){ objCache.company[id]=res.data; for(var i = 0 ;i < ha.length;++i){ ha[i](true,res.data); } }else{ for(var i = 0 ;i < ha.length;++i){ ha[i](false); } } }, error:function(dfd){ ha[i](false); } }); } }; var cacheModel={ getProfessor:function(id,cb){ var val =objCache.professor[id] if(val){ cb(true,val); }else{ if(objHCache.professor[id]){ objHCache.professor[id].push(cb); }else{ objHCache.professor[id]=[]; objHCache.professor[id].push(cb); objCacheHandler.professor(id); } } }, getCompany:function(id,cb){ var val =objCache.company[id] if(val){ cb(true,val); }else{ if(objHCache.company[id]){ objHCache.company[id].push(cb); }else{ objHCache.company[id]=[]; objHCache.company[id].push(cb); objCacheHandler.company(id); } } } }; window.cacheModel = cacheModel; })(window)