Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export interface ICacheOptions {
backend: any;
namespace: string;
policy: ICachePolicy;
prunecallback? : ((keys : string[]) => void);
}

export interface ICachePolicy {
Expand All @@ -14,11 +15,13 @@ export default class Cache {
protected backend: any;
protected namespace: string;
protected policy: ICachePolicy;
protected prunecallback? : ((keys : string[]) => void);

constructor(options: ICacheOptions) {
this.namespace = options.namespace;
this.backend = options.backend;
this.policy = options.policy;
this.prunecallback = options.prunecallback;
let ttl = this.policy.stdTTL;
if (!ttl || typeof(ttl) !== 'number') {
ttl = 0;
Expand Down Expand Up @@ -53,6 +56,10 @@ export default class Cache {

await Promise.all(removePromises);

if(this.prunecallback !== undefined && victimList.length > 0){
this.prunecallback(victimList);
}

const survivorList = lru.slice(victimCount);
return this.setLRU(survivorList);
}
Expand Down