blob: 43dd6b4a73b91f800962fd113acc082bab8291e2 (
plain)
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
44
|
export default class Cache {
constructor() {
this._data = {};
}
has(key) {
return this._data.hasOwnProperty(key);
}
get(key) {
if(this.has(key)) {
return this._data[key].value;
}
return null;
}
set(key, value, type = null) {
this._data[key] = {value, type};
}
remove(key) {
delete this._data[key];
}
clear() {
this._data = {};
}
getByType(type) {
let results = [];
for(let key in this._data) {
if(!this._data.hasOwnProperty(key)) continue;
let element = this._data[key];
if(element.type === type) {
results.push(element.value);
}
}
return results;
}
}
|