From 94217e9e1a0f106d7c0e8f75022bed739aee388b Mon Sep 17 00:00:00 2001 From: Justin Wind Date: Thu, 10 Jul 2025 16:12:06 -0700 Subject: [PATCH] track age in arc --- lib/arc.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/arc.js b/lib/arc.js index f784109..0281878 100644 --- a/lib/arc.js +++ b/lib/arc.js @@ -20,6 +20,7 @@ class ARCache extends EventEmitter { frequent; // Frequent LRU recentGhost; // Recent history LRU frequentGhost; // Frequent historic LRU + age; // Tally of total get attempts, for statistics eventData; // Object spread over all event data /** @@ -85,19 +86,30 @@ class ARCache extends EventEmitter { capacity: frequentCapacity, evictDestination: this.frequentGhost, }); + + this.age = 0; } + /** + * @returns {number} capacity of the cache + */ get capacity() { return this._capacity; } + /** + * @returns {number} capacity of the adaptive cache + */ get adaptiveCapacity() { return this._adaptiveCapacity; } + /** + * @returns {number} entries in the cache + */ get size() { return this.recent.size + this.frequent.size + this.recentGhost.size + this.frequentGhost.size; } @@ -109,10 +121,12 @@ class ARCache extends EventEmitter { * @param {boolean} isGhost hit from ghost cache */ _hit(entry, isGhost = false) { + this.age += 1; this.emit('hit', { ...this.eventData, key: entry.key, count: entry.count, + age: this.age - entry.ts, isGhost, }); } @@ -123,6 +137,7 @@ class ARCache extends EventEmitter { * @param {*} key key */ _miss(key) { + this.age += 1; this.emit('miss', { ...this.eventData, key, -- 2.49.1