From 77feba43eb03eb5201ef77a3606178533390e579 Mon Sep 17 00:00:00 2001 From: Duell10111 Date: Tue, 26 Jan 2021 15:33:11 +0100 Subject: [PATCH 1/2] Added PruneCallback to cache.ts --- src/cache.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cache.ts b/src/cache.ts index 3f7153a..a8d0c15 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -3,6 +3,7 @@ export interface ICacheOptions { backend: any; namespace: string; policy: ICachePolicy; + prunecallback? : ((keys : string[]) => void); } export interface ICachePolicy { @@ -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; @@ -53,6 +56,10 @@ export default class Cache { await Promise.all(removePromises); + if(this.prunecallback !== undefined){ + this.prunecallback(victimList); + } + const survivorList = lru.slice(victimCount); return this.setLRU(survivorList); } From 69c001280ddf434bee8eecd2ddb21e4fecebe08e Mon Sep 17 00:00:00 2001 From: Duell10111 Date: Wed, 27 Jan 2021 00:42:03 +0100 Subject: [PATCH 2/2] Changed to call callback only when victimlist is not empty --- src/cache.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cache.ts b/src/cache.ts index a8d0c15..41831e6 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -56,7 +56,7 @@ export default class Cache { await Promise.all(removePromises); - if(this.prunecallback !== undefined){ + if(this.prunecallback !== undefined && victimList.length > 0){ this.prunecallback(victimList); }