当前位置: 代码迷 >> Web前端 >> 利用闭包兑现缓存
  详细解决方案

利用闭包兑现缓存

热度:184   发布时间:2012-11-06 14:07:00.0
利用闭包实现缓存
var cacheTest = function(){
var cache = {}, count=[];
return {
attachSearch: function(id){
if(id in cache){
return cache[id];
}
if(count.length > 2){
delete cache[count.shift()];
}
cache[id] = id;
count.push(id);
return id;
}
}
}();
  相关解决方案