4 changed files with 53 additions and 15 deletions
@ -0,0 +1,34 @@ |
|||||
|
|
||||
|
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{ |
||||
|
} |
||||
|
|
||||
Loading…
Reference in new issue