Merge commit '12fce6c' into HEAD
# Conflicts: # index.js # src/configs/index.js # src/configs/machineGroupControl.json # src/helper/assetUtils.js # src/helper/childRegistrationUtils.js # src/helper/configUtils.js # src/helper/logger.js # src/helper/menuUtils.js # src/helper/menuUtils_DEPRECATED.js # src/helper/outputUtils.js # src/helper/validationUtils.js # src/measurements/Measurement.js # src/measurements/MeasurementContainer.js # src/measurements/examples.js # src/outliers/outlierDetection.js
This commit is contained in:
@@ -2,10 +2,11 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
class AssetLoader {
|
||||
constructor() {
|
||||
constructor(maxCacheSize = 100) {
|
||||
this.relPath = './'
|
||||
this.baseDir = path.resolve(__dirname, this.relPath);
|
||||
this.cache = new Map(); // Cache loaded JSON files for better performance
|
||||
this.cache = new Map();
|
||||
this.maxCacheSize = maxCacheSize;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,7 +51,11 @@ class AssetLoader {
|
||||
const rawData = fs.readFileSync(filePath, 'utf8');
|
||||
const assetData = JSON.parse(rawData);
|
||||
|
||||
// Cache the result
|
||||
// Cache the result (evict oldest if at capacity)
|
||||
if (this.cache.size >= this.maxCacheSize) {
|
||||
const oldestKey = this.cache.keys().next().value;
|
||||
this.cache.delete(oldestKey);
|
||||
}
|
||||
this.cache.set(cacheKey, assetData);
|
||||
|
||||
return assetData;
|
||||
|
||||
Reference in New Issue
Block a user