Deepen supercomputer category with shared base and expanded APIs.

Adds supercomputer-base helpers, richer job/shard/steal/thermal modules,
priority jobs, claimMatching, and bumps all 14 modules to 0.3.1.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Raven Scott
2026-05-21 01:40:29 -04:00
co-authored by Cursor
parent cacab441af
commit d89b56d782
32 changed files with 446 additions and 74 deletions
+26 -1
View File
@@ -2,6 +2,7 @@ require('bare-process/global')
const EventEmitter = require('bare-events')
const b4a = require('b4a')
const { initModuleSwarm, gossipSend } = require('../../_shared/p2p-bare.js')
const { clusterStats } = require('../../_shared/supercomputer-base.js')
const PROTOCOL = 'cache-farm/v1'
@@ -77,6 +78,30 @@ class HyperP2PCacheFarm extends EventEmitter {
keys () { return [...this._cache.keys()] }
getOrPut (key, factory) {
const hit = this.get(key)
if (hit !== undefined) return hit
const value = typeof factory === 'function' ? factory() : factory
this.put(key, value)
return value
}
hitRate () {
const total = this._stats.hits + this._stats.misses
return total ? this._stats.hits / total : 0
}
purgeExpired () {
let n = 0
for (const [k, entry] of this._cache) {
if (entry.expiresAt && Date.now() > entry.expiresAt) {
this._cache.delete(k)
n++
}
}
return n
}
async ready () {
if (this.swarm || !this.topic) return this
await initModuleSwarm(this, {
@@ -90,7 +115,7 @@ class HyperP2PCacheFarm extends EventEmitter {
}
getStats () {
return { ...this._stats, entries: this._cache.size, protocol: PROTOCOL }
return clusterStats(this._stats, PROTOCOL, { entries: this._cache.size, hitRate: this.hitRate() })
}
async close () {
@@ -1,6 +1,6 @@
{
"name": "hyper-p2p-cache-farm",
"version": "0.3.0",
"version": "0.3.1",
"description": "Distributed LRU cache farm for Bare/Pear P2P supercomputer mesh.",
"main": "index.js",
"type": "commonjs",