pub struct InvalidationContext {
pub modified_views: Vec<String>,
pub reason: InvalidationReason,
}Expand description
Context for cache invalidation operations.
Encapsulates which views/tables were modified and why, providing structured information for logging and debugging.
§Example
use fraiseql_core::cache::InvalidationContext;
// Invalidate after mutation
let ctx = InvalidationContext::for_mutation(
"createUser",
vec!["v_user".to_string()]
);
// Invalidate manually
let ctx = InvalidationContext::manual(
vec!["v_user".to_string(), "v_post".to_string()],
"data import completed"
);
// Invalidate on schema change
let ctx = InvalidationContext::schema_change(
vec!["v_user".to_string()],
"1.0.0",
"1.1.0"
);Fields§
§modified_views: Vec<String>List of views/tables that were modified.
All cache entries accessing these views will be invalidated.
reason: InvalidationReasonReason for invalidation.
Used for structured logging and debugging.
Implementations§
Source§impl InvalidationContext
impl InvalidationContext
Sourcepub fn for_mutation(mutation_name: &str, modified_views: Vec<String>) -> Self
pub fn for_mutation(mutation_name: &str, modified_views: Vec<String>) -> Self
Create invalidation context for a mutation.
Used by mutation handlers to invalidate cache entries after modifying data.
§Arguments
mutation_name- Name of the mutation (e.g., “createUser”)modified_views- List of views/tables modified by the mutation
§Example
use fraiseql_core::cache::InvalidationContext;
let ctx = InvalidationContext::for_mutation(
"createUser",
vec!["v_user".to_string()]
);
assert_eq!(ctx.modified_views, vec!["v_user"]);Sourcepub fn manual(modified_views: Vec<String>, reason: &str) -> Self
pub fn manual(modified_views: Vec<String>, reason: &str) -> Self
Create invalidation context for manual invalidation.
Used by administrators or background jobs to manually invalidate cache entries (e.g., after data import, during maintenance).
§Arguments
modified_views- List of views/tables to invalidatereason- Human-readable reason for audit logging
§Example
use fraiseql_core::cache::InvalidationContext;
let ctx = InvalidationContext::manual(
vec!["v_user".to_string(), "v_post".to_string()],
"maintenance: rebuilding indexes"
);
assert_eq!(ctx.modified_views.len(), 2);Sourcepub fn schema_change(
affected_views: Vec<String>,
old_version: &str,
new_version: &str,
) -> Self
pub fn schema_change( affected_views: Vec<String>, old_version: &str, new_version: &str, ) -> Self
Create invalidation context for schema change.
Used during deployments when the schema version changes to flush all cached entries that depend on the old schema structure.
§Arguments
affected_views- All views in the schema (typically all views)old_version- Previous schema versionnew_version- New schema version
§Example
use fraiseql_core::cache::InvalidationContext;
let ctx = InvalidationContext::schema_change(
vec!["v_user".to_string(), "v_post".to_string()],
"1.0.0",
"1.1.0"
);
assert_eq!(ctx.modified_views.len(), 2);Sourcepub fn to_log_string(&self) -> String
pub fn to_log_string(&self) -> String
Get a log-friendly description of this invalidation.
§Example
use fraiseql_core::cache::InvalidationContext;
let ctx = InvalidationContext::for_mutation(
"createUser",
vec!["v_user".to_string()]
);
assert_eq!(
ctx.to_log_string(),
"mutation:createUser affecting 1 view(s)"
);Sourcepub fn view_count(&self) -> usize
pub fn view_count(&self) -> usize
Get the number of views affected by this invalidation.
§Example
use fraiseql_core::cache::InvalidationContext;
let ctx = InvalidationContext::manual(
vec!["v_user".to_string(), "v_post".to_string()],
"maintenance"
);
assert_eq!(ctx.view_count(), 2);Sourcepub fn affects_view(&self, view: &str) -> bool
pub fn affects_view(&self, view: &str) -> bool
Check if this invalidation affects a specific view.
§Arguments
view- View name to check
§Example
use fraiseql_core::cache::InvalidationContext;
let ctx = InvalidationContext::for_mutation(
"createUser",
vec!["v_user".to_string(), "v_post".to_string()]
);
assert!(ctx.affects_view("v_user"));
assert!(ctx.affects_view("v_post"));
assert!(!ctx.affects_view("v_comment"));Trait Implementations§
Source§impl Clone for InvalidationContext
impl Clone for InvalidationContext
Source§fn clone(&self) -> InvalidationContext
fn clone(&self) -> InvalidationContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more