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
impl Resolver
Sourcepub fn new() -> Self
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.
Sourcepub fn set_primary_cache(&self, backend: CacheBackendRef)
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).
Sourcepub fn set_persistent_cache(&self, backend: CacheBackendRef)
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.
Sourcepub fn set_hooks(&self, hooks: HooksRef)
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.
Sourcepub fn clear_hooks(&self)
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).
Sourcepub fn register_provider(
&self,
kind: &str,
provider: Arc<dyn DataSourceProvider>,
)
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.
Sourcepub fn provider_kinds(&self) -> Vec<String>
pub fn provider_kinds(&self) -> Vec<String>
Snapshot the registered provider kinds. Useful for tests and host-app diagnostics.
Sourcepub fn key_for(spec: &InlineData, namespace: Option<&str>) -> u64
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|”).
Sourcepub async fn fetch(
&self,
key: u64,
request: FetchRequest,
) -> Result<ResolveOutcome, FetchError>
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.
Sourcepub async fn invalidate(&self, key: u64)
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.
Sourcepub async fn invalidate_all(&self)
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).
Sourcepub async fn invalidate_by_slug(&self, slug: &str)
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.
Sourcepub async fn invalidate_by_namespace(&self, namespace: &str)
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.