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
§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)
§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
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CascadeInvalidator
impl Debug for CascadeInvalidator
Source§impl Default for CascadeInvalidator
impl Default for CascadeInvalidator
Source§impl<'de> Deserialize<'de> for CascadeInvalidator
impl<'de> Deserialize<'de> for CascadeInvalidator
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for CascadeInvalidator
impl RefUnwindSafe for CascadeInvalidator
impl Send for CascadeInvalidator
impl Sync for CascadeInvalidator
impl Unpin for CascadeInvalidator
impl UnsafeUnpin for CascadeInvalidator
impl UnwindSafe for CascadeInvalidator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more