From: Justin Wind Date: Thu, 10 Jul 2025 23:12:06 +0000 (-0700) Subject: track age in arc X-Git-Url: http://git.squeep.com/?a=commitdiff_plain;p=squeep-cache track age in arc --- 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,