559340
在TJ的Connect模块中看到Cache中一个LRU算法,太简单了,一起品一下:
Cache.prototype.add = function(key){
// initialize store
var len = this.keys.push(key);//在数组最后添加一个元素
// limit reached, invalidate LRU
if (len > this.limit) this.remove(this.keys.shift());//删除数组的第一个元素
var arr = this.store[key] = [];//这里为什么赋值为空数组???
arr.createdAt = new Date;
return arr;
};