HttpCacheInterface

Trait HttpCacheInterface 

Source
pub trait HttpCacheInterface<B = Vec<u8>>: Send + Sync {
    // Required methods
    fn analyze_request(
        &self,
        parts: &Parts,
        mode_override: Option<CacheMode>,
    ) -> Result<CacheAnalysis>;
    async fn lookup_cached_response(
        &self,
        key: &str,
    ) -> Result<Option<(HttpResponse, CachePolicy)>>;
    async fn process_response(
        &self,
        analysis: CacheAnalysis,
        response: Response<B>,
    ) -> Result<Response<B>>;
    fn prepare_conditional_request(
        &self,
        parts: &mut Parts,
        cached_response: &HttpResponse,
        policy: &CachePolicy,
    ) -> Result<()>;
    async fn handle_not_modified(
        &self,
        cached_response: HttpResponse,
        fresh_parts: &Parts,
    ) -> Result<HttpResponse>;
}
Expand description

An interface for HTTP caching that works with composable middleware patterns like Tower. This trait separates the concerns of request analysis, cache lookup, and response processing into discrete steps.

Required Methods§

Source

fn analyze_request( &self, parts: &Parts, mode_override: Option<CacheMode>, ) -> Result<CacheAnalysis>

Analyze a request to determine cache behavior

Source

async fn lookup_cached_response( &self, key: &str, ) -> Result<Option<(HttpResponse, CachePolicy)>>

Look up a cached response for the given cache key

Source

async fn process_response( &self, analysis: CacheAnalysis, response: Response<B>, ) -> Result<Response<B>>

Process a fresh response from upstream and potentially cache it

Source

fn prepare_conditional_request( &self, parts: &mut Parts, cached_response: &HttpResponse, policy: &CachePolicy, ) -> Result<()>

Update request headers for conditional requests (e.g., If-None-Match)

Source

async fn handle_not_modified( &self, cached_response: HttpResponse, fresh_parts: &Parts, ) -> Result<HttpResponse>

Handle a 304 Not Modified response by returning the cached response

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§