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§
Sourcefn analyze_request(
&self,
parts: &Parts,
mode_override: Option<CacheMode>,
) -> Result<CacheAnalysis>
fn analyze_request( &self, parts: &Parts, mode_override: Option<CacheMode>, ) -> Result<CacheAnalysis>
Analyze a request to determine cache behavior
Sourceasync fn lookup_cached_response(
&self,
key: &str,
) -> Result<Option<(HttpResponse, CachePolicy)>>
async fn lookup_cached_response( &self, key: &str, ) -> Result<Option<(HttpResponse, CachePolicy)>>
Look up a cached response for the given cache key
Sourceasync fn process_response(
&self,
analysis: CacheAnalysis,
response: Response<B>,
) -> Result<Response<B>>
async fn process_response( &self, analysis: CacheAnalysis, response: Response<B>, ) -> Result<Response<B>>
Process a fresh response from upstream and potentially cache it
Sourcefn prepare_conditional_request(
&self,
parts: &mut Parts,
cached_response: &HttpResponse,
policy: &CachePolicy,
) -> Result<()>
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)
Sourceasync fn handle_not_modified(
&self,
cached_response: HttpResponse,
fresh_parts: &Parts,
) -> Result<HttpResponse>
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.