MCPcopy Create free account
hub / github.com/erans/pgsqlite / cache_statement_metadata

Method cache_statement_metadata

src/cache/enhanced_statement_pool.rs:289–324  ·  view source on GitHub ↗

Cache statement metadata with optimization data

(
        &self,
        cache_key: String,
        metadata: StatementMetadata,
        pattern: QueryPattern,
        hints: OptimizationHints,
    )

Source from the content-addressed store, hash-verified

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 {

Callers 1

Calls 5

evict_least_valuableMethod · 0.80
lenMethod · 0.45
cloneMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected