Cache statement metadata with optimization data
(
&self,
cache_key: String,
metadata: StatementMetadata,
pattern: QueryPattern,
hints: OptimizationHints,
)
| 287 | |
| 288 | /// Cache statement metadata with optimization data |
| 289 | fn cache_statement_metadata( |
| 290 | &self, |
| 291 | cache_key: String, |
| 292 | metadata: StatementMetadata, |
| 293 | pattern: QueryPattern, |
| 294 | hints: OptimizationHints, |
| 295 | ) { |
| 296 | let mut statements = self.statements.write().unwrap(); |
| 297 | |
| 298 | // Check if we need to evict entries |
| 299 | if statements.len() >= self.max_size { |
| 300 | self.evict_least_valuable(&mut statements); |
| 301 | } |
| 302 | |
| 303 | // Calculate priority score for this entry |
| 304 | let priority_score = self.calculate_priority_score(&pattern, &hints); |
| 305 | |
| 306 | let entry = CachedStatementEntry { |
| 307 | metadata, |
| 308 | pattern: pattern.clone(), |
| 309 | hints, |
| 310 | access_count: 0, |
| 311 | last_used: Instant::now(), |
| 312 | created_at: Instant::now(), |
| 313 | avg_execution_time: None, |
| 314 | priority_score, |
| 315 | }; |
| 316 | |
| 317 | statements.insert(cache_key, entry); |
| 318 | |
| 319 | // Update pattern statistics |
| 320 | { |
| 321 | let mut stats = self.stats.write().unwrap(); |
| 322 | *stats.most_accessed_patterns.entry(pattern).or_insert(0) += 1; |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | /// Calculate priority score for caching decisions |
| 327 | fn calculate_priority_score(&self, pattern: &QueryPattern, hints: &OptimizationHints) -> f64 { |
no test coverage detected