Skip to main content

StreamingCacheManager

Trait StreamingCacheManager 

Source
pub trait StreamingCacheManager:
    Send
    + Sync
    + 'static {
    type Body: Body + Send + 'static;

    // Required methods
    fn get(
        &self,
        cache_key: &str,
    ) -> impl Future<Output = Result<Option<(Response<Self::Body>, CachePolicy)>>> + Send
       where <Self::Body as Body>::Data: Send,
             <Self::Body as Body>::Error: Into<StreamingError> + Send + Sync + 'static;
    fn put<B>(
        &self,
        cache_key: String,
        response: Response<B>,
        policy: CachePolicy,
        request_url: Url,
        metadata: Option<Vec<u8>>,
    ) -> impl Future<Output = Result<Response<Self::Body>>> + Send
       where B: Body + Send + 'static,
             B::Data: Send,
             B::Error: Into<StreamingError>,
             <Self::Body as Body>::Data: Send,
             <Self::Body as Body>::Error: Into<StreamingError> + Send + Sync + 'static;
    fn update_metadata(
        &self,
        cache_key: &str,
        headers: &HeaderMap,
        policy: CachePolicy,
        user_metadata: Option<Vec<u8>>,
        token: Option<&CacheEntryToken>,
    ) -> impl Future<Output = Result<bool>> + Send;
    fn convert_body<B>(
        &self,
        response: Response<B>,
    ) -> impl Future<Output = Result<Response<Self::Body>>> + Send
       where B: Body + Send + 'static,
             B::Data: Send,
             B::Error: Into<StreamingError>,
             <Self::Body as Body>::Data: Send,
             <Self::Body as Body>::Error: Into<StreamingError> + Send + Sync + 'static;
    fn delete(&self, cache_key: &str) -> impl Future<Output = Result<()>> + Send;
    fn empty_body(&self) -> Self::Body;
}
Expand description

A streaming cache manager that supports streaming request/response bodies without buffering them in memory. This is ideal for large responses.

Required Associated Types§

Source

type Body: Body + Send + 'static

The body type used by this cache manager

Required Methods§

Source

fn get( &self, cache_key: &str, ) -> impl Future<Output = Result<Option<(Response<Self::Body>, CachePolicy)>>> + Send
where <Self::Body as Body>::Data: Send, <Self::Body as Body>::Error: Into<StreamingError> + Send + Sync + 'static,

Attempts to pull a cached response and related policy from cache with streaming body.

Source

fn put<B>( &self, cache_key: String, response: Response<B>, policy: CachePolicy, request_url: Url, metadata: Option<Vec<u8>>, ) -> impl Future<Output = Result<Response<Self::Body>>> + Send
where B: Body + Send + 'static, B::Data: Send, B::Error: Into<StreamingError>, <Self::Body as Body>::Data: Send, <Self::Body as Body>::Error: Into<StreamingError> + Send + Sync + 'static,

Attempts to cache a response with a streaming body and related policy.

After put() resolves, the cache entry is durable and visible at-or-after full consumption of the returned body. The current implementation commits before returning; callers must not rely on the stronger property.

Source

fn update_metadata( &self, cache_key: &str, headers: &HeaderMap, policy: CachePolicy, user_metadata: Option<Vec<u8>>, token: Option<&CacheEntryToken>, ) -> impl Future<Output = Result<bool>> + Send

Update the stored headers, cache policy, and user metadata for an existing entry WITHOUT touching the body file. Used by 304 revalidation, where the body is known-unchanged.

If token is Some, the update is applied only when the stored entry still matches that identity; Ok(false) means the entry no longer exists or was concurrently replaced — callers should serve the response and skip re-caching.

Source

fn convert_body<B>( &self, response: Response<B>, ) -> impl Future<Output = Result<Response<Self::Body>>> + Send
where B: Body + Send + 'static, B::Data: Send, B::Error: Into<StreamingError>, <Self::Body as Body>::Data: Send, <Self::Body as Body>::Error: Into<StreamingError> + Send + Sync + 'static,

Converts a generic body to the manager’s body type for non-cacheable responses. This is called when a response should not be cached but still needs to be returned with the correct body type.

Source

fn delete(&self, cache_key: &str) -> impl Future<Output = Result<()>> + Send

Attempts to remove a record from cache.

Source

fn empty_body(&self) -> Self::Body

Creates an empty body of the manager’s body type. Used for returning 504 Gateway Timeout responses on OnlyIfCached cache misses.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§