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>
impl<V> FactoryContext<V>
Sourcepub fn options_mut(&mut self) -> &mut EntryOptions
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.
Sourcepub fn options(&self) -> &EntryOptions
pub fn options(&self) -> &EntryOptions
The options for the value being produced.
Sourcepub fn adapt<F>(&mut self, f: F)
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)));Sourcepub fn has_stale_value(&self) -> bool
pub fn has_stale_value(&self) -> bool
true if a previously-cached (now stale) value is available.
Sourcepub fn stale_value(&self) -> Option<&V>
pub fn stale_value(&self) -> Option<&V>
The previously-cached (now stale) value, if any.
Sourcepub fn stale_etag(&self) -> Option<&str>
pub fn stale_etag(&self) -> Option<&str>
The ETag of the stale value, for issuing a conditional request.
Sourcepub fn stale_last_modified(&self) -> Option<Timestamp>
pub fn stale_last_modified(&self) -> Option<Timestamp>
The LastModified of the stale value, for issuing a conditional request.
Sets the tags for the value being produced (adaptive tagging). Overrides
the tags passed to the get_or_set call.
Sourcepub fn value(self, value: V) -> FactoryProduct<V>
pub fn value(self, value: V) -> FactoryProduct<V>
Produces a new value, cached with the current (possibly adapted) options.
Sourcepub fn modified(self, value: V) -> ModifiedBuilder<V>
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.
Sourcepub fn fail(&self, message: impl Into<String>) -> FactoryError
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>
impl<V: Clone> FactoryContext<V>
Sourcepub fn not_modified(self) -> Result<FactoryProduct<V>, FactoryError>
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.