|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
/* ======================================== LRU 最近最少使用 ======================================== */
function
FifoCache(limit){
limit = limit||10;
var
_store = [];
var
index = {};
this
.get =
function
(key){
var
ind = index[key];
return
_store[ind];
};
this
.set =
function
(key,value){
if
(_store.length>=limit){
_store.shift();
for
(
var
k
in
index){
index[k] = index[k]-1;
}
}
var
length = _store.push(value);
index[key] = length-1;
};
this
.list =
function
(){
console.log(_store);
};
}
|
本文转自 antlove 51CTO博客,原文链接:http://blog.51cto.com/antlove/1978074