Trait CacheStorage

Source
pub trait CacheStorage:
    Send
    + Sync
    + 'static {
    // Required methods
    fn get<B: HttpBody>(
        &self,
        key: &str,
    ) -> impl Future<Output = Result<Option<StoredResponse<B>>>> + Send;
    fn put(
        &self,
        key: &str,
        parts: &Parts,
        policy: &CachePolicy,
        digest: &str,
    ) -> impl Future<Output = Result<()>> + Send;
    fn put_with_body<B: HttpBody>(
        &self,
        key: &str,
        parts: &Parts,
        policy: &CachePolicy,
        body: B,
    ) -> impl Future<Output = Result<(Body<B>, String)>> + Send;
    fn delete(&self, key: &str) -> impl Future<Output = Result<()>> + Send;
    fn body_path(&self, digest: &str) -> PathBuf;
}
Expand description

A trait implemented on cache storage.

Cache keys are strings of hexadecimal characters.

Required Methods§

Source

fn get<B: HttpBody>( &self, key: &str, ) -> impl Future<Output = Result<Option<StoredResponse<B>>>> + Send

Gets a previously stored response for the given response key.

Returns Ok(None) if a response does not exist in the storage for the given response key.

Source

fn put( &self, key: &str, parts: &Parts, policy: &CachePolicy, digest: &str, ) -> impl Future<Output = Result<()>> + Send

Puts a response with an existing content digest into the storage for the given response key.

The provided content digest must come from a previous call to CacheStorage::get.

Source

fn put_with_body<B: HttpBody>( &self, key: &str, parts: &Parts, policy: &CachePolicy, body: B, ) -> impl Future<Output = Result<(Body<B>, String)>> + Send

Puts a response with supplied body into the storage for the given response key.

Returns the body from the cache along with its digest upon success.

Source

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

Deletes a previously cached response for the given response key.

Deleting an unknown key is not considered an error.

Source

fn body_path(&self, digest: &str) -> PathBuf

Gets the path to a response body for the given content digest.

This method does not verify the content’s existence.

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§