Fix sorting bug in validationUtils and add cache cap to AssetLoader
- validationUtils: unsorted x values now actually sorted (was returning false) - validationUtils: duplicate x values now actually removed (was returning false) - validationUtils: areNumbers check no longer skipped after sort/dedup - AssetLoader: add maxCacheSize (default 100) with LRU-style eviction Closes #21, closes #24 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,10 +2,11 @@ const fs = require('fs');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
class AssetLoader {
|
class AssetLoader {
|
||||||
constructor() {
|
constructor(maxCacheSize = 100) {
|
||||||
this.relPath = './'
|
this.relPath = './'
|
||||||
this.baseDir = path.resolve(__dirname, 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 rawData = fs.readFileSync(filePath, 'utf8');
|
||||||
const assetData = JSON.parse(rawData);
|
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);
|
this.cache.set(cacheKey, assetData);
|
||||||
|
|
||||||
return assetData;
|
return assetData;
|
||||||
|
|||||||
Reference in New Issue
Block a user