diff --git a/@xen-orchestra/xapi/host.mjs b/@xen-orchestra/xapi/host.mjs index 037e2abc3c1..854d8c8ea7f 100644 --- a/@xen-orchestra/xapi/host.mjs +++ b/@xen-orchestra/xapi/host.mjs @@ -1,4 +1,4 @@ -import LRU from 'lru-cache' +import TTLCache from '@isaacs/ttlcache' import { asyncEach } from '@vates/async-each' import { asyncMap } from '@xen-orchestra/async-map' import { decorateClass } from '@vates/decorate-with' @@ -44,9 +44,9 @@ const IPMI_SENSOR_REGEX_BY_PRODUCT_NAME = Object.keys(IPMI_SENSOR_REGEX_BY_DATA_ {} ) -const IPMI_CACHE = new LRU({ - max: MAX_HOSTS_PER_POOL, +const IPMI_CACHE = new TTLCache({ ttl: IPMI_CACHE_TTL, + max: MAX_HOSTS_PER_POOL, }) const waitAgentRestart = (xapi, hostRef, prevAgentStartTime) => @@ -182,17 +182,11 @@ class Host { } async getIpmiSensors(ref) { - const cache = IPMI_CACHE.get(ref) - if (cache !== undefined) { - return cache - } - const productName = (await this.getField('host', ref, 'bios_strings'))['system-product-name']?.toLowerCase() if (IPMI_SENSOR_REGEX_BY_DATA_TYPE_BY_SUPPORTED_PRODUCT_NAME[productName] === undefined) { - IPMI_CACHE.set(ref, {}) return {} } - const callSensorPlugin = fn => this.callAsync('host.call_plugin', ref, '2crsi-sensors.py', fn, {}) + const callSensorPlugin = fn => this.call(IPMI_CACHE, 'host.call_plugin', ref, '2crsi-sensors.py', fn, {}) // https://github.com/AtaxyaNetwork/xcp-ng-xapi-plugins/tree/ipmi-sensors?tab=readme-ov-file#ipmi-sensors-parser const [stringifiedIpmiSensors, ip] = await Promise.all([callSensorPlugin('get_info'), callSensorPlugin('get_ip')]) const ipmiSensors = JSON.parse(stringifiedIpmiSensors) @@ -217,8 +211,6 @@ class Host { ipmiSensorsByDataType[IPMI_SENSOR_DATA_TYPE.generalInfo] = { ip } - IPMI_CACHE.set(ref, ipmiSensorsByDataType) - return ipmiSensorsByDataType } } diff --git a/@xen-orchestra/xapi/package.json b/@xen-orchestra/xapi/package.json index 442532a469d..c5af1e9bc04 100644 --- a/@xen-orchestra/xapi/package.json +++ b/@xen-orchestra/xapi/package.json @@ -23,6 +23,7 @@ "test": "node--test" }, "dependencies": { + "@isaacs/ttlcache": "^1.4.1", "@vates/async-each": "^1.0.0", "@vates/decorate-with": "^2.1.0", "@vates/nbd-client": "^3.0.2", @@ -34,7 +35,6 @@ "http-request-plus": "^1.0.0", "json-rpc-protocol": "^0.13.2", "lodash": "^4.17.15", - "lru-cache": "^7.0.4", "promise-toolbox": "^0.21.0", "vhd-lib": "^4.11.0", "xo-common": "^0.8.0" diff --git a/yarn.lock b/yarn.lock index 3857f228511..64ea0da6c7d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2362,6 +2362,11 @@ make-error "^1.1.1" v8-compile-cache-lib "^3.0.1" +"@isaacs/ttlcache@^1.4.1": + version "1.4.1" + resolved "https://registry.yarnpkg.com/@isaacs/ttlcache/-/ttlcache-1.4.1.tgz#21fb23db34e9b6220c6ba023a0118a2dd3461ea2" + integrity sha512-RQgQ4uQ+pLbqXfOmieB91ejmLwvSgv9nLx6sT6sD83s7umBypgg+OIBOBbEUiJXrfpnp9j0mRhYYdzp9uqq3lA== + "@istanbuljs/load-nyc-config@^1.0.0": version "1.1.0" resolved "https://registry.yarnpkg.com/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz#fd3db1d59ecf7cf121e80650bb86712f9b55eced"