@papicandela/mcx-core 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +11 -2
- package/package.json +1 -1
- package/src/sandbox/analyzer/analyzer.ts +18 -4
package/dist/index.js
CHANGED
|
@@ -6005,14 +6005,23 @@ var allRules = [
|
|
|
6005
6005
|
];
|
|
6006
6006
|
|
|
6007
6007
|
// src/sandbox/analyzer/analyzer.ts
|
|
6008
|
+
var CACHE_MAX_SIZE = 10;
|
|
6008
6009
|
var visitorMapCache = new Map;
|
|
6009
6010
|
function getVisitorMap(rules, config) {
|
|
6010
6011
|
const cacheKey = JSON.stringify(config.rules);
|
|
6011
6012
|
let map = visitorMapCache.get(cacheKey);
|
|
6012
|
-
if (
|
|
6013
|
-
|
|
6013
|
+
if (map) {
|
|
6014
|
+
visitorMapCache.delete(cacheKey);
|
|
6014
6015
|
visitorMapCache.set(cacheKey, map);
|
|
6016
|
+
return map;
|
|
6015
6017
|
}
|
|
6018
|
+
map = buildVisitorMap(rules, config);
|
|
6019
|
+
if (visitorMapCache.size >= CACHE_MAX_SIZE) {
|
|
6020
|
+
const oldest = visitorMapCache.keys().next().value;
|
|
6021
|
+
if (oldest)
|
|
6022
|
+
visitorMapCache.delete(oldest);
|
|
6023
|
+
}
|
|
6024
|
+
visitorMapCache.set(cacheKey, map);
|
|
6016
6025
|
return map;
|
|
6017
6026
|
}
|
|
6018
6027
|
function buildVisitorMap(rules, config) {
|
package/package.json
CHANGED
|
@@ -36,21 +36,35 @@ import { allRules } from "./rules/index.js";
|
|
|
36
36
|
*/
|
|
37
37
|
type VisitorMap = Map<string, Array<{ rule: Rule; visitor: Rule["visitors"][string] }>>;
|
|
38
38
|
|
|
39
|
-
// Cache for visitor maps - keyed by stringified rules config
|
|
39
|
+
// Cache for visitor maps - keyed by stringified rules config (LRU with max 10 entries)
|
|
40
|
+
const CACHE_MAX_SIZE = 10;
|
|
40
41
|
const visitorMapCache = new Map<string, VisitorMap>();
|
|
41
42
|
|
|
42
43
|
/**
|
|
43
|
-
* Get or build a visitor map (cached for performance)
|
|
44
|
+
* Get or build a visitor map (cached for performance with LRU eviction)
|
|
44
45
|
*/
|
|
45
46
|
function getVisitorMap(rules: Rule[], config: Required<AnalysisConfig>): VisitorMap {
|
|
46
47
|
// Create cache key from rules config
|
|
47
48
|
const cacheKey = JSON.stringify(config.rules);
|
|
48
49
|
|
|
49
50
|
let map = visitorMapCache.get(cacheKey);
|
|
50
|
-
if (
|
|
51
|
-
|
|
51
|
+
if (map) {
|
|
52
|
+
// Move to end for LRU (delete and re-add)
|
|
53
|
+
visitorMapCache.delete(cacheKey);
|
|
52
54
|
visitorMapCache.set(cacheKey, map);
|
|
55
|
+
return map;
|
|
53
56
|
}
|
|
57
|
+
|
|
58
|
+
// Build new map
|
|
59
|
+
map = buildVisitorMap(rules, config);
|
|
60
|
+
|
|
61
|
+
// Evict oldest if at capacity
|
|
62
|
+
if (visitorMapCache.size >= CACHE_MAX_SIZE) {
|
|
63
|
+
const oldest = visitorMapCache.keys().next().value;
|
|
64
|
+
if (oldest) visitorMapCache.delete(oldest);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
visitorMapCache.set(cacheKey, map);
|
|
54
68
|
return map;
|
|
55
69
|
}
|
|
56
70
|
|