From 1e2d806d25e4683b99c4196be9785aab431d47c0 Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Mon, 11 Dec 2023 12:04:55 -0800 Subject: [PATCH] Fix LRUCache eviction --- package.json | 2 +- src/util/LRUCache.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 23939c3..ac41a8b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "paravel", - "version": "0.4.13", + "version": "0.4.14", "description": "Yet another toolkit for nostr", "author": "hodlbod", "license": "MIT", diff --git a/src/util/LRUCache.ts b/src/util/LRUCache.ts index 10892c5..0282d26 100644 --- a/src/util/LRUCache.ts +++ b/src/util/LRUCache.ts @@ -12,7 +12,11 @@ export class LRUCache { const v = this.map.get(k) if (v !== undefined) { - this.keys.push(this.keys.shift() as T) + this.keys.push(k as T) + + if (this.keys.length > this.maxSize) { + this.keys.splice(-this.maxSize) + } } return v