Skip to main content

Context

Trait Context 

Source
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

  • CacheFuture creates a Box<dyn Context> at the start
  • Context is passed as &mut BoxContext through backend operations
  • Backends can upgrade the context type via *ctx = Box::new(NewContext { ... })
  • Format uses &dyn Context for policy hints during serialization
  • At the end, convert to CacheContext via into_cache_context()

Required Methods§

Source

fn status(&self) -> CacheStatus

Returns the cache status.

Source

fn set_status(&mut self, status: CacheStatus)

Sets the cache status.

Source

fn source(&self) -> &ResponseSource

Returns the response source.

Source

fn set_source(&mut self, source: ResponseSource)

Sets the response source.

Source

fn as_any(&self) -> &dyn Any

Returns a reference to self as Any for downcasting.

Source

fn clone_box(&self) -> BoxContext

Clone this context into a box.

Source

fn into_cache_context(self: Box<Self>) -> CacheContext

Consumes boxed self and returns a CacheContext.

Provided Methods§

Source

fn read_mode(&self) -> ReadMode

Returns the read mode for this context.

Source

fn set_read_mode(&mut self, _mode: ReadMode)

Sets the read mode.

Source

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 from
  • prefix - Label prefix to prepend to source path (e.g., backend label)

Implementors§