-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCache.js
More file actions
43 lines (42 loc) · 1.06 KB
/
Cache.js
File metadata and controls
43 lines (42 loc) · 1.06 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
dojo.provide("cvdj.Ca");
cvdj.Cache = function() {
// summary
// return an object of type cvdj.Cache
var k = [];
var c = {};
var max = 10;
this.count = k.length;
this.add = function(/* str */key, /* object */val) {
for ( var i = 0; i < k.length; i++) {
if (k[i] == key) {
k.splice(i, 1);
break;
}
}
this.count = k.push(key);
c[key] = val;
this.count = k.length;
this._prune();
console.log(k);
};
this._prune = function() {
while (k.length > max) {
var v = k.shift();
if (typeof c[v].destroy == 'function') {
c[v].destroy();
}
delete c[v];
}
this.count = k.length;
};
this.get = function(/* str */key) {
for ( var i = 0; i < k.length; i++) {
if (k[i] == key) {
k.splice(i, 1);
this.count = k.push(key);
return c[k];
}
}
return false;
};
};