Skip to main content

CascadeInvalidator

Struct CascadeInvalidator 

Source
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_analytics

Implementations§

Source§

impl CascadeInvalidator

Source

pub fn new() -> Self

Create new cascade invalidator.

Source

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 another
  • dependency_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();
Source

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
  1. Start with the target view
  2. Find all views that directly depend on it
  3. For each dependent, recursively find views that depend on it
  4. 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"));
Source

pub fn get_direct_dependents(&self, view: &str) -> HashSet<String>

Get all views that depend on a given view (direct dependents only).

For transitive dependents, use cascade_invalidate().

§Arguments
  • view - View to query
§Returns

Set of views that directly depend on the given view

Source

pub fn get_direct_dependencies(&self, view: &str) -> HashSet<String>

Get all views that a given view depends on (direct dependencies only).

§Arguments
  • view - View to query
§Returns

Set of views that the given view depends on

Source

pub fn get_transitive_dependents(&self, view: &str) -> HashSet<String>

Get all views that transitively depend on a given view.

Like cascade_invalidate() but non-mutating (for queries).

§Arguments
  • view - View to query
§Returns

Set of all transitive dependents (including the view itself)

Source

pub fn has_dependency_path(&self, dependent: &str, dependency: &str) -> bool

Check if there’s a dependency path between two views.

Returns true if dependent transitively depends on dependency.

§Arguments
  • dependent - Potentially dependent view
  • dependency - Potentially depended-upon view
§Returns

true if there’s a transitive dependency

Source

pub fn stats(&self) -> InvalidationStats

Get cascade invalidation statistics.

Source

pub fn clear(&mut self)

Clear all registered dependencies.

Source

pub fn view_count(&self) -> usize

Get total number of views tracked.

Source

pub fn dependency_count(&self) -> usize

Get total number of dependency edges.

Trait Implementations§

Source§

impl Clone for CascadeInvalidator

Source§

fn clone(&self) -> CascadeInvalidator

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CascadeInvalidator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CascadeInvalidator

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for CascadeInvalidator

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for CascadeInvalidator

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,