pub trait Context: Send + Sync {
// Required methods
fn status(&self) -> CacheStatus;
fn set_status(&mut self, status: CacheStatus);
fn source(&self) -> &ResponseSource;
fn set_source(&mut self, source: ResponseSource);
fn as_any(&self) -> &dyn Any;
fn clone_box(&self) -> BoxContext;
fn into_cache_context(self: Box<Self>) -> CacheContext;
// Provided methods
fn read_mode(&self) -> ReadMode { ... }
fn set_read_mode(&mut self, _mode: ReadMode) { ... }
fn merge_from(&mut self, other: &dyn Context, prefix: &BackendLabel) { ... }
}Expand description
Unified context for cache operations.
This trait combines operation tracking (status, source) with backend policy hints. It allows a single context object to flow through the entire cache pipeline, being transformed as needed by different layers.
§Usage
CacheFuturecreates aBox<dyn Context>at the start- Context is passed as
&mut BoxContextthrough backend operations - Backends can upgrade the context type via
*ctx = Box::new(NewContext { ... }) - Format uses
&dyn Contextfor policy hints during serialization - At the end, convert to
CacheContextviainto_cache_context()
Required Methods§
Sourcefn status(&self) -> CacheStatus
fn status(&self) -> CacheStatus
Returns the cache status.
Sourcefn set_status(&mut self, status: CacheStatus)
fn set_status(&mut self, status: CacheStatus)
Sets the cache status.
Sourcefn source(&self) -> &ResponseSource
fn source(&self) -> &ResponseSource
Returns the response source.
Sourcefn set_source(&mut self, source: ResponseSource)
fn set_source(&mut self, source: ResponseSource)
Sets the response source.
Sourcefn clone_box(&self) -> BoxContext
fn clone_box(&self) -> BoxContext
Clone this context into a box.
Sourcefn into_cache_context(self: Box<Self>) -> CacheContext
fn into_cache_context(self: Box<Self>) -> CacheContext
Consumes boxed self and returns a CacheContext.
Provided Methods§
Sourcefn set_read_mode(&mut self, _mode: ReadMode)
fn set_read_mode(&mut self, _mode: ReadMode)
Sets the read mode.
Sourcefn merge_from(&mut self, other: &dyn Context, prefix: &BackendLabel)
fn merge_from(&mut self, other: &dyn Context, prefix: &BackendLabel)
Merge fields from another context into this one.
Used by composition backends to combine results from inner backends.
The prefix is prepended to the source path for hierarchical naming.
§Arguments
other- The inner context to merge fromprefix- Label prefix to prepend to source path (e.g., backend label)