MCPcopy
hub / github.com/opentrace/opentrace / cacheNode

Method cacheNode

ui/src/store/ladybugStore.ts:743–764  ·  view source on GitHub ↗

Set a node in the LRU cache, evicting oldest entries if over capacity.

(
    id: string,
    entry: { type: string; name: string; properties: Record<string, unknown> },
  )

Source from the content-addressed store, hash-verified

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. */

Callers 2

importDatabaseMethod · 0.95
flushMethod · 0.95

Calls 1

deleteMethod · 0.65

Tested by

no test coverage detected