pub struct CascadeInvalidator { /* private fields */ }Expand description
Tracks transitive view-to-view dependencies for cascading invalidation.
§Architecture
When v_user depends on v_raw_user, and v_analytics depends on v_user:
v_raw_user (source)
↓ (depends on)
v_user (intermediate)
↓ (depends on)
v_analytics (leaf)Invalidating v_raw_user cascades to invalidate v_user and v_analytics.
§Example
use fraiseql_core::cache::cascade_invalidator::CascadeInvalidator;
let mut invalidator = CascadeInvalidator::new();
// Register that v_user depends on v_raw_user
invalidator.add_dependency("v_user", "v_raw_user").unwrap();
// Register that v_analytics depends on v_user
invalidator.add_dependency("v_analytics", "v_user").unwrap();
// Invalidate v_raw_user - cascades to v_user and v_analytics
let affected = invalidator.cascade_invalidate("v_raw_user").unwrap();
assert_eq!(affected.len(), 3); // v_raw_user, v_user, v_analyticsImplementations§
Source§impl CascadeInvalidator
impl CascadeInvalidator
Sourcepub fn add_dependency(
&mut self,
dependent_view: &str,
dependency_view: &str,
) -> Result<()>
pub fn add_dependency( &mut self, dependent_view: &str, dependency_view: &str, ) -> Result<()>
Register a view dependency.
Declares that dependent_view depends on dependency_view.
When dependency_view is invalidated, dependent_view will also be invalidated.
§Arguments
dependent_view- View that depends on anotherdependency_view- View that is depended upon
§Errors
Returns FraiseQLError::Validation if dependent_view and
dependency_view are the same (self-dependency), or if adding the edge
would create a cycle in the dependency graph.
§Example
use fraiseql_core::cache::cascade_invalidator::CascadeInvalidator;
let mut invalidator = CascadeInvalidator::new();
invalidator.add_dependency("v_analytics", "v_user").unwrap();Sourcepub fn cascade_invalidate(&mut self, view: &str) -> Result<HashSet<String>>
pub fn cascade_invalidate(&mut self, view: &str) -> Result<HashSet<String>>
Cascade invalidate a view and all dependent views.
Uses breadth-first search to find all views that transitively depend on the given view, and returns the complete set of invalidated views.
§Algorithm
- Start with the target view
- Find all views that directly depend on it
- For each dependent, recursively find views that depend on it
- Return complete set (target + all transitive dependents)
§Arguments
view- View to invalidate
§Returns
Set of all invalidated views (including the target)
§Errors
Currently infallible — always returns Ok. The Result return type is
reserved for future cycle-detection logic that may return
FraiseQLError::Validation on circular dependency graphs.
§Example
use fraiseql_core::cache::cascade_invalidator::CascadeInvalidator;
let mut invalidator = CascadeInvalidator::new();
invalidator.add_dependency("v_user_stats", "v_user").unwrap();
invalidator.add_dependency("v_dashboard", "v_user_stats").unwrap();
let invalidated = invalidator.cascade_invalidate("v_user").unwrap();
assert!(invalidated.contains("v_user"));
assert!(invalidated.contains("v_user_stats"));
assert!(invalidated.contains("v_dashboard"));Sourcepub fn get_direct_dependents(&self, view: &str) -> HashSet<String>
pub fn get_direct_dependents(&self, view: &str) -> HashSet<String>
Sourcepub fn get_direct_dependencies(&self, view: &str) -> HashSet<String>
pub fn get_direct_dependencies(&self, view: &str) -> HashSet<String>
Sourcepub fn get_transitive_dependents(&self, view: &str) -> HashSet<String>
pub fn get_transitive_dependents(&self, view: &str) -> HashSet<String>
Sourcepub fn has_dependency_path(&self, dependent: &str, dependency: &str) -> bool
pub fn has_dependency_path(&self, dependent: &str, dependency: &str) -> bool
Sourcepub fn stats(&self) -> InvalidationStats
pub fn stats(&self) -> InvalidationStats
Get cascade invalidation statistics.
Sourcepub fn view_count(&self) -> usize
pub fn view_count(&self) -> usize
Get total number of views tracked.
Sourcepub fn dependency_count(&self) -> usize
pub fn dependency_count(&self) -> usize
Get total number of dependency edges.
Trait Implementations§
Source§impl Clone for CascadeInvalidator
impl Clone for CascadeInvalidator
Source§fn clone(&self) -> CascadeInvalidator
fn clone(&self) -> CascadeInvalidator
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more