Skip to main content

FactoryContext

Struct FactoryContext 

Source
pub struct FactoryContext<V> { /* private fields */ }
Expand description

Context passed to a factory, carrying stale-value information and the mutable options for the value being produced.

Implementations§

Source§

impl<V> FactoryContext<V>

Source

pub fn key(&self) -> &str

The (prefixed) cache key being produced.

Source

pub fn options_mut(&mut self) -> &mut EntryOptions

The options for the value being produced. Mutate these to adapt the caching of this specific value (e.g. shorten the duration for an empty result). This is adaptive caching.

Source

pub fn options(&self) -> &EntryOptions

The options for the value being produced.

Source

pub fn adapt<F>(&mut self, f: F)

Adapts the options for the value being produced using the chainable builder methods — the ergonomic way to do adaptive caching:

ⓘ
ctx.adapt(|o| o.with_duration(Duration::from_secs(5)));
Source

pub fn has_stale_value(&self) -> bool

true if a previously-cached (now stale) value is available.

Source

pub fn stale_value(&self) -> Option<&V>

The previously-cached (now stale) value, if any.

Source

pub fn stale_etag(&self) -> Option<&str>

The ETag of the stale value, for issuing a conditional request.

Source

pub fn stale_last_modified(&self) -> Option<Timestamp>

The LastModified of the stale value, for issuing a conditional request.

Source

pub fn set_tags<I, S>(&mut self, tags: I)
where I: IntoIterator<Item = S>, S: AsRef<str>,

Sets the tags for the value being produced (adaptive tagging). Overrides the tags passed to the get_or_set call.

Source

pub fn value(self, value: V) -> FactoryProduct<V>

Produces a new value, cached with the current (possibly adapted) options.

Source

pub fn modified(self, value: V) -> ModifiedBuilder<V>

Begins producing a modified value, allowing an ETag/LastModified (and tags) to be attached for future conditional refreshes.

Source

pub fn fail(&self, message: impl Into<String>) -> FactoryError

Signals a factory failure, returning a FactoryError to return as Err. Triggers the fail-safe path.

Source§

impl<V: Clone> FactoryContext<V>

Source

pub fn not_modified(self) -> Result<FactoryProduct<V>, FactoryError>

Signals that the resource has not changed (e.g. an HTTP 304): the stale value is reused as the fresh result and its expiration is bumped using the current options. Fails if there is no stale value to reuse.

Trait Implementations§

Source§

impl<V: Debug> Debug for FactoryContext<V>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<V> Freeze for FactoryContext<V>
where Option<V>: Freeze,

§

impl<V> RefUnwindSafe for FactoryContext<V>

§

impl<V> Send for FactoryContext<V>
where Option<V>: Send,

§

impl<V> Sync for FactoryContext<V>
where Option<V>: Sync,

§

impl<V> Unpin for FactoryContext<V>
where Option<V>: Unpin,

§

impl<V> UnsafeUnpin for FactoryContext<V>
where Option<V>: UnsafeUnpin,

§

impl<V> UnwindSafe for FactoryContext<V>
where Option<V>: UnwindSafe,

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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