MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / insert

Method insert

nodedb/src/engine/timeseries/query_cache.rs:50–78  ·  view source on GitHub ↗

Insert a result into the cache. Evicts old entries if over budget.

(&mut self, tenant_id: u64, partition_id: i64, query_hash: u64, result: Vec<u8>)

Source from the content-addressed store, hash-verified

48
49 /// Insert a result into the cache. Evicts old entries if over budget.
50 pub fn insert(&mut self, tenant_id: u64, partition_id: i64, query_hash: u64, result: Vec<u8>) {
51 let key = (tenant_id, partition_id, query_hash);
52
53 // Don't cache if the single entry exceeds budget.
54 if result.len() > self.max_bytes {
55 return;
56 }
57
58 // Remove old entry for this key if exists.
59 if let Some(old) = self.entries.remove(&key) {
60 self.current_bytes -= old.len();
61 self.order.retain(|k| k != &key);
62 }
63
64 // Evict until we have room.
65 while self.current_bytes + result.len() > self.max_bytes {
66 if let Some(evict_key) = self.order.pop_front() {
67 if let Some(evicted) = self.entries.remove(&evict_key) {
68 self.current_bytes -= evicted.len();
69 }
70 } else {
71 break;
72 }
73 }
74
75 self.current_bytes += result.len();
76 self.order.push_back(key);
77 self.entries.insert(key, result);
78 }
79
80 /// Invalidate all cached entries for a partition (e.g., if it's modified).
81 ///

Callers 5

basic_cache_roundtripFunction · 0.45
tenant_isolationFunction · 0.45
lru_evictionFunction · 0.45
invalidate_partitionFunction · 0.45
evict_tenantFunction · 0.45

Calls 3

pop_frontMethod · 0.80
lenMethod · 0.45
removeMethod · 0.45

Tested by 5

basic_cache_roundtripFunction · 0.36
tenant_isolationFunction · 0.36
lru_evictionFunction · 0.36
invalidate_partitionFunction · 0.36
evict_tenantFunction · 0.36