Skip to main content

DialCache

Struct DialCache 

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

A cache instance: request, process-local and remote layers behind explicit enablement.

Instances are cheap to clone and share one state.

Implementations§

Source§

impl DialCache

Source

pub fn builder() -> DialCacheBuilder

Start configuring an instance with the defaults documented on DialCacheBuilder’s setters.

Source

pub fn namespace(&self) -> &str

The instance namespace.

Source

pub fn enable_guard(&self) -> ScopeGuard

Open the outermost enabled scope and hold it in a guard. The scope closes when the guard drops; retained Scope clones then pass through.

ⓘ
let request = cache.enable_guard();
let name = display_name.get(request.scope(), id).await?;
Source

pub async fn enable<F, Fut, R>(&self, f: F) -> R
where F: FnOnce(Scope) -> Fut, Fut: Future<Output = R>,

Open the outermost enabled scope for f. The scope closes when the returned future completes, is dropped before completion, or unwinds; retained clones then pass through.

Source

pub async fn enable_in<F, Fut, R>(&self, parent: &Scope, f: F) -> R
where F: FnOnce(Scope) -> Fut, Fut: Future<Output = R>,

Enable caching inside parent, reusing its live outer request memo. When parent has no live outer scope, this opens a new one.

Source

pub async fn disable_in<F, Fut, R>(&self, parent: &Scope, f: F) -> R
where F: FnOnce(Scope) -> Fut, Fut: Future<Output = R>,

Disable caching inside parent while preserving its outer request memo for nested re-enablement.

Source

pub fn is_enabled(&self, scope: &Scope) -> bool

Whether calls made with scope on this instance use caching.

Source

pub fn coalescing_state(&self) -> CoalescingState

Process-scoped single-flight state of this instance.

Source

pub async fn invalidate( &self, key_type: &str, id: impl IntoKeyId, future_buffer_ms: u64, ) -> Result<(), Error>

Advance the invalidation watermark of every tracked variant of one entity, in this instance’s namespace. Call it after the source mutation commits. Requires a remote adapter; failures are returned. IDs use the same IntoKeyId conversion as crate::KeySpec::new.

Source

pub async fn invalidate_identity( &self, identity: Identity, future_buffer_ms: u64, ) -> Result<(), Error>

Advance the watermark for the entity named by identity after its source mutation commits. An empty namespace inherits this instance’s; an explicit namespace is preserved, exactly as in get_or_load.

All use cases and argument variants share the entity’s watermark. tracked is ignored: this operation always invalidates tracked remote values. Local entries and already acquired snapshots retain their lifetimes. Requires a remote adapter; mutation failures are returned to the caller.

Source

pub async fn get_or_load<T, F, Fut>( &self, scope: &Scope, operation: Operation<T>, load: F, ) -> Result<Arc<T>, Error>
where T: Send + Sync + 'static, F: Fn(Scope) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<T, BoxError>> + Send + 'static,

Execute one inline cached call.

load is the source of truth; it may be invoked again later by served-hit shadow validation, so it must be reusable. The returned value is shared by reference: treat it as immutable.

Source§

impl DialCache

Source

pub fn use_case<Args, T>( &self, key_type: impl Into<String>, use_case: impl Into<String>, ) -> UseCaseBuilder<Args, T>
where Args: Clone + Send + Sync + 'static, T: Send + Sync + 'static,

Start registering a use case. key_type names the entity type and use_case the operation; the pair identifies cached values.

Trait Implementations§

Source§

impl Clone for DialCache

Source§

fn clone(&self) -> DialCache

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for DialCache

Source§

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

Formats the value using the given formatter. 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, 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> 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.