Skip to main content

QueryCacheCoordinator

Struct QueryCacheCoordinator 

Source
pub struct QueryCacheCoordinator { /* private fields */ }
Expand description

Coordinates query-result caching: owns the QueryCache, the reverse table -> query index used for mutation invalidation, and the auth-scope derivation that keys cache entries per principal.

Splitting these out of super::router::FunctionRouter keeps the router focused on dispatch and lets the cache concerns be tested in isolation.

Implementations§

Source§

impl QueryCacheCoordinator

Source

pub fn new(registry: &FunctionRegistry) -> Self

Create a coordinator from the function registry. The reverse index is built once at construction so mutation invalidation is a hash lookup.

Source

pub fn get_by_scope( &self, function_name: &str, args: &Value, scope: Option<&str>, ) -> Option<Arc<Value>>

Lookup a cached value with an already-derived scope. Use this when the caller has computed Self::auth_scope up front (e.g. before auth is moved into a context).

Source

pub fn set_by_scope( &self, function_name: &str, args: &Value, scope: Option<&str>, value: Value, ttl: Duration, )

Store a value with an already-derived scope.

Source

pub fn set_arc_by_scope( &self, function_name: &str, args: &Value, scope: Option<&str>, value: Arc<Value>, ttl: Duration, )

Store a pre-wrapped Arc<Value> with an already-derived scope.

Source

pub fn invalidate_for_mutation(&self, info: &FunctionInfo)

Invalidate cached queries whose table dependencies overlap with the mutation’s write set, narrowed by column intersection when both sides know which columns they touch.

Conservative on uncertainty: when either the mutation’s changed_columns or the candidate query’s selected_columns is empty (extractor couldn’t determine columns from the SQL), the query is invalidated. False positives are cheap (re-execute a query); false negatives would serve stale data.

Source

pub fn invalidate_by_change(&self, change: &Change)

Invalidate cached queries affected by a forge_changes NOTIFY event.

Used to propagate mutations across cluster nodes: every node listening to forge_changes runs this for each peer-emitted change so its local cache stays consistent. Without this, mutations on node A leave stale cache entries on node B until TTL expires.

Mirrors invalidate_for_mutation’s column-intersection logic but uses the change’s runtime changed_columns rather than the mutation’s compile-time set. An empty change column list means “could be any column” (older trigger payloads, INSERT/DELETE) — fall back to full invalidation for that table.

Source

pub fn spawn_cluster_invalidator( self: Arc<Self>, rx: Receiver<Change>, ) -> JoinHandle<()>

Spawn a background task that drains a Change broadcast and evicts matching cache entries. Returns a handle the caller can abort on shutdown. The receiver typically comes from Reactor::change_subscriber().

Source

pub fn auth_scope(auth: &AuthContext) -> Option<String>

Derive a stable cache scope from auth context. Anonymous callers share the "anon" scope; authenticated callers get a hash that mixes role + claims so cross-tenant cache bleed is impossible.

Volatile JWT claims (iat, nbf, exp, jti, auth_time, sid, nonce) are excluded — they change on every token refresh for the same logical principal and would otherwise fragment the cache, killing hit rate for any system using refresh tokens.

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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, 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