projects
/
squeep-cache
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
bbf8141
)
track age in arc
master
author
Justin Wind
<justin.wind+git@gmail.com>
Thu, 10 Jul 2025 23:12:06 +0000
(16:12 -0700)
committer
Justin Wind
<justin.wind+git@gmail.com>
Thu, 10 Jul 2025 23:12:06 +0000
(16:12 -0700)
lib/arc.js
patch
|
blob
|
history
diff --git
a/lib/arc.js
b/lib/arc.js
index f78410924b7e303209da467e5444ab79216736e1..0281878c400b408f54452f4ad1b18564f230a861 100644
(file)
--- 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
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
/**
eventData; // Object spread over all event data
/**
@@
-85,19
+86,30
@@
class ARCache extends EventEmitter {
capacity: frequentCapacity,
evictDestination: this.frequentGhost,
});
capacity: frequentCapacity,
evictDestination: this.frequentGhost,
});
+
+ this.age = 0;
}
}
+ /**
+ * @returns {number} capacity of the cache
+ */
get capacity() {
return this._capacity;
}
get capacity() {
return this._capacity;
}
+ /**
+ * @returns {number} capacity of the adaptive cache
+ */
get adaptiveCapacity() {
return this._adaptiveCapacity;
}
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;
}
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) {
* @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,
this.emit('hit', {
...this.eventData,
key: entry.key,
count: entry.count,
+ age: this.age - entry.ts,
isGhost,
});
}
isGhost,
});
}
@@
-123,6
+137,7
@@
class ARCache extends EventEmitter {
* @param {*} key key
*/
_miss(key) {
* @param {*} key key
*/
_miss(key) {
+ this.age += 1;
this.emit('miss', {
...this.eventData,
key,
this.emit('miss', {
...this.eventData,
key,