Skip to main content

Resolver

Struct Resolver 

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

Provider dispatch + cache + dedup orchestration.

One Resolver per ChartML instance. The resolver is held inside ChartML as SharedRef<Resolver> (Arc on native, Rc on WASM) so consumers can grab a handle for the invalidate* API while the chart instance keeps using it.

Implementations§

Source§

impl Resolver

Source

pub fn new() -> Self

New resolver with the default MemoryBackend as tier-1, no tier-2, and no providers registered. ChartML::new() registers the built-in inline + http providers immediately after construction.

Source

pub fn set_primary_cache(&self, backend: CacheBackendRef)

Replace the tier-1 cache backend. Used by ChartML::set_cache. The fresh backend starts empty — entries in the old backend are not migrated (caller’s responsibility if they want to).

Source

pub fn set_persistent_cache(&self, backend: CacheBackendRef)

Set the optional tier-2 (persistent) cache. Phase 3 leaves this public so phase 3b’s IndexedDbBackend can wire in without further surface changes.

Source

pub fn set_hooks(&self, hooks: HooksRef)

Register a ResolverHooks impl. Replaces any previously registered hooks; passes the new impl in as a HooksRef (Arc on native, Rc on WASM). After this call every Resolver::fetch invocation emits progress / cache / error events through the new impl.

Source

pub fn clear_hooks(&self)

Clear any previously registered hooks. Subsequent fetch calls behave as if set_hooks had never been called (no-op emission).

Source

pub fn register_provider( &self, kind: &str, provider: Arc<dyn DataSourceProvider>, )

Register a provider under a dispatch key ("inline", "http", "datasource", or any custom slug). Re-registration replaces the previously registered provider for that key.

Source

pub fn provider_kinds(&self) -> Vec<String>

Snapshot the registered provider kinds. Useful for tests and host-app diagnostics.

Source

pub fn key_for(spec: &InlineData, namespace: Option<&str>) -> u64

Compute the cache key the resolver would use for a given spec.

Public so phase 4 (Leptos refresh button) and phase 6 (Kyomi invalidate-on-change) can compute the exact key the resolver caches under without re-implementing the hash.

Hashes (namespace, datasource, query, url, provider, rows_hash) in that order. None fields contribute a sentinel byte (0xFE, an invalid UTF-8 start byte) so they cannot collide with a real string value of "None". Field separator is 0xFF (also invalid UTF-8) so adjacent fields can’t bleed into each other (“a|b” vs “ab|”).

Source

pub async fn fetch( &self, key: u64, request: FetchRequest, ) -> Result<ResolveOutcome, FetchError>

The core orchestration: tier-1 → tier-2 → in-flight dedup → provider.

Returns ResolveOutcome (result + cache-hit flag) so the caller can classify the source under cache_hits vs cache_misses in FetchMetadata. Tier-1 hits hydrate from memory only; tier-2 hits also re-populate tier-1 so subsequent reads in the same session short-circuit.

Source

pub async fn invalidate(&self, key: u64)

Drop a single entry from every cache tier. The next miss on key will be reported via hooks::ResolverHooks::on_cache_miss with hooks::MissReason::Invalidated rather than NotFound.

Source

pub async fn invalidate_all(&self)

Drop every cached entry across all tiers. The very next miss on any key will be reported as Invalidated; subsequent misses fall back to the regular NotFound / Expired reasoning. See the field-level docs on Resolver::recently_invalidated for why per-key tracking isn’t done here (would require a keys() method on every backend).

Source

pub async fn invalidate_by_slug(&self, slug: &str)

Drop every entry whose source spec carried the given datasource slug. Useful for “datasource X was edited; invalidate all queries against it” workflows. Subject to the same single-shot Invalidated reporting as Resolver::invalidate_all.

Source

pub async fn invalidate_by_namespace(&self, namespace: &str)

Drop every entry tagged with the given namespace. Used for tenant isolation flows (“user logged out; clear their cached data”). Subject to the same single-shot Invalidated reporting as Resolver::invalidate_all.

Source

pub async fn shutdown(&self)

Iterate every registered provider AND cache backend, awaiting their shutdown hook in turn. Wired up by ChartML::shutdown().

Trait Implementations§

Source§

impl Debug for Resolver

Source§

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

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

impl Default for Resolver

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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, 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<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> Allocation for T
where T: RefUnwindSafe + Send + Sync,