Get cached plan if available
(&self, key: &PlanCacheKey)
| 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( |
no test coverage detected