diff --git a/datasets/assetData/curves/index.js b/datasets/assetData/curves/index.js index c5d3dd4..93aa2fb 100644 --- a/datasets/assetData/curves/index.js +++ b/datasets/assetData/curves/index.js @@ -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; } /** @@ -46,7 +47,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;