Invalidate caches when schema changes
(&self, table: String, change_type: String)
| 447 | |
| 448 | /// Invalidate caches when schema changes |
| 449 | pub fn invalidate_on_schema_change(&self, table: String, change_type: String) { |
| 450 | let mut schema_version = self.schema_version.write().unwrap(); |
| 451 | *schema_version += 1; |
| 452 | |
| 453 | // Create schema change event |
| 454 | let schema_change_type = match change_type.as_str() { |
| 455 | "table_created" => super::invalidation::SchemaChangeType::TableCreated, |
| 456 | "table_dropped" => super::invalidation::SchemaChangeType::TableDropped, |
| 457 | "column_added" => super::invalidation::SchemaChangeType::ColumnAdded, |
| 458 | "column_dropped" => super::invalidation::SchemaChangeType::ColumnDropped, |
| 459 | "column_modified" => super::invalidation::SchemaChangeType::ColumnModified, |
| 460 | "constraint_added" => super::invalidation::SchemaChangeType::ConstraintAdded, |
| 461 | "constraint_dropped" => super::invalidation::SchemaChangeType::ConstraintDropped, |
| 462 | _ => super::invalidation::SchemaChangeType::ColumnModified, |
| 463 | }; |
| 464 | |
| 465 | let event = InvalidationEvent::SchemaChange { |
| 466 | table, |
| 467 | change_type: schema_change_type, |
| 468 | }; |
| 469 | |
| 470 | // Handle invalidation through the manager |
| 471 | let result = self.invalidation_manager.handle_event(event.clone()); |
| 472 | |
| 473 | // Invalidate plan cache entries with old schema version |
| 474 | self.plan_cache.invalidate_by_schema(*schema_version); |
| 475 | |
| 476 | // Also invalidate result cache and subquery cache since plans may have changed |
| 477 | let graph_version = *self.graph_version.read().unwrap(); |
| 478 | self.result_cache.invalidate_by_graph_version(graph_version); |
| 479 | self.subquery_cache |
| 480 | .invalidate_by_schema_version(*schema_version); |
| 481 | |
| 482 | self.record_event(CacheEvent::Invalidation { |
| 483 | strategy: result.strategy_used, |
| 484 | affected_entries: result.entries_invalidated, |
| 485 | timestamp: Instant::now(), |
| 486 | }); |
| 487 | |
| 488 | self.update_global_stats(); |
| 489 | } |
| 490 | |
| 491 | /// Get comprehensive cache statistics |
| 492 | pub fn get_stats(&self) -> CacheManagerStats { |
no test coverage detected