You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
632 B
35 lines
632 B
|
4 years ago
|
|
||
|
|
export class CacheTable{
|
||
|
|
|
||
|
|
constructor(threshold){
|
||
|
|
this.entries = {};
|
||
|
|
this.count = 0;
|
||
|
|
this.threshold = threshold || 1024;
|
||
|
|
}
|
||
|
|
set(key, val){
|
||
|
|
if(this.entries[key] === undefined){
|
||
|
|
if(this.count < this.threshold){
|
||
|
|
this.count++;
|
||
|
|
}else{
|
||
|
|
for(var otherKey in this.entries){
|
||
|
|
delete this.entries[otherKey];
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
this.entries[key] = val;
|
||
|
|
}
|
||
|
|
remove(key){
|
||
|
|
if(this.entries[key] !== undefined){
|
||
|
|
delete this.entries[key];
|
||
|
|
this.count--;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
get(key){ return this.entries[key]; }
|
||
|
|
allEntries(){ return this.entries; }
|
||
|
|
}
|
||
|
|
|
||
|
|
export class SpamTable{
|
||
|
|
}
|
||
|
|
|