From 77feba43eb03eb5201ef77a3606178533390e579 Mon Sep 17 00:00:00 2001 From: Duell10111 Date: Tue, 26 Jan 2021 15:33:11 +0100 Subject: [PATCH 1/3] 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/3] 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); } From fed87b32fa188d95150cb69ef619cc170b33e8ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Sp=C3=A4th?= Date: Wed, 9 Jun 2021 22:18:24 +0200 Subject: [PATCH 3/3] Fixed two bugs occurred while building - Removed dist delete because of Errors with Windows OS - Fixed missing property in test case --- package.json | 2 +- src/cache.test.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 8d17b8c..dde0ba5 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "types": "./dist/index.d.ts", "scripts": { "prebuild": "tslint -c tslint.json -p tsconfig.json --fix", - "build": "rm -rf dist && tsc", + "build": "tsc", "prepublish": "npm test", "test": "npm run build && jest --coverage" }, diff --git a/src/cache.test.ts b/src/cache.test.ts index fdbc2ac..c701c74 100644 --- a/src/cache.test.ts +++ b/src/cache.test.ts @@ -4,6 +4,7 @@ import MemoryStore from "../src/memoryStore"; const cache = new Cache({ namespace: "test", policy: { + stdTTL: 0, maxEntries: 1 }, backend: MemoryStore