MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / get

Method get

graphlite/src/cache/plan_cache.rs:133–178  ·  view source on GitHub ↗

Get cached plan if available

(&self, key: &PlanCacheKey)

Source from the content-addressed store, hash-verified

131
132 /// Get cached plan if available
133 pub fn get(&self, key: &PlanCacheKey) -> Option<PlanCacheEntry> {
134 let mut entries = self.entries.write().unwrap();
135
136 if let Some(entry) = entries.get_mut(key) {
137 if entry.is_valid() {
138 // Update access info
139 entry.metadata.update_access();
140 entry.usage_count += 1;
141 entry.last_used = Instant::now();
142
143 // Update stats
144 {
145 let mut stats = self.stats.write().unwrap();
146 stats.hits += 1;
147 stats.compilations_saved += 1;
148 stats.total_compilation_time_saved_ms +=
149 entry.compilation_time.as_millis() as u64;
150 }
151
152 Some(entry.clone())
153 } else {
154 // Remove expired entry
155 let removed_entry = entries.remove(key).unwrap();
156 let size = removed_entry.size_bytes();
157
158 {
159 let mut current_memory = self.current_memory.write().unwrap();
160 *current_memory = current_memory.saturating_sub(size);
161 }
162
163 {
164 let mut stats = self.stats.write().unwrap();
165 stats.misses += 1;
166 stats.current_entries = entries.len();
167 stats.current_memory_bytes = *self.current_memory.read().unwrap();
168 }
169
170 None
171 }
172 } else {
173 // Cache miss
174 let mut stats = self.stats.write().unwrap();
175 stats.misses += 1;
176 None
177 }
178 }
179
180 /// Insert plan into cache
181 pub fn insert(

Callers 5

get_query_resultMethod · 0.45
get_query_planMethod · 0.45
get_subquery_resultMethod · 0.45

Calls 8

unwrapMethod · 0.80
get_mutMethod · 0.80
update_accessMethod · 0.80
cloneMethod · 0.80
is_validMethod · 0.45
removeMethod · 0.45
size_bytesMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected