Set a node in the LRU cache, evicting oldest entries if over capacity.
(
id: string,
entry: { type: string; name: string; properties: Record<string, unknown> },
)
| 741 | |
| 742 | /** Set a node in the LRU cache, evicting oldest entries if over capacity. */ |
| 743 | private cacheNode( |
| 744 | id: string, |
| 745 | entry: { type: string; name: string; properties: Record<string, unknown> }, |
| 746 | ): void { |
| 747 | // Delete first so re-insert moves to end (most recent) |
| 748 | this.nodeCache.delete(id); |
| 749 | this.nodeCache.set(id, entry); |
| 750 | // Evict oldest entries if over capacity |
| 751 | if (this.nodeCache.size > LadybugGraphStore.NODE_CACHE_MAX) { |
| 752 | const it = this.nodeCache.keys(); |
| 753 | // Delete oldest 10% in one pass to avoid per-insert eviction churn |
| 754 | const evictCount = Math.max( |
| 755 | 1, |
| 756 | this.nodeCache.size - LadybugGraphStore.NODE_CACHE_MAX, |
| 757 | ); |
| 758 | for (let i = 0; i < evictCount; i++) { |
| 759 | const oldest = it.next(); |
| 760 | if (oldest.done) break; |
| 761 | this.nodeCache.delete(oldest.value); |
| 762 | } |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | /** Search stored source files for exact text patterns (regex). |
| 767 | * Yields to the event loop every GREP_YIELD_INTERVAL files to avoid blocking the UI. */ |
no test coverage detected