Trait zng::task::http::CacheDb

source ·
pub trait CacheDb:
    Send
    + Sync
    + 'static {
    // Required methods
    fn clone_boxed(&self) -> Box<dyn CacheDb>;
    fn policy<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 CacheKey,
    ) -> Pin<Box<dyn Future<Output = Option<CachePolicy>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn set_policy<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 CacheKey,
        policy: CachePolicy,
    ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn body<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 CacheKey,
    ) -> Pin<Box<dyn Future<Output = Option<Body>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn set<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 CacheKey,
        policy: CachePolicy,
        body: Body,
    ) -> Pin<Box<dyn Future<Output = Option<Body>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn remove<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 CacheKey,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn purge<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
    fn prune<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
}
Expand description

Represents a download cache in a Client.

Cache implementers must store a CachePolicy and Body for a given CacheKey.

Required Methods§

source

fn clone_boxed(&self) -> Box<dyn CacheDb>

Dynamic clone.

source

fn policy<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 CacheKey, ) -> Pin<Box<dyn Future<Output = Option<CachePolicy>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Retrieves the cache-policy for the given key.

source

fn set_policy<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 CacheKey, policy: CachePolicy, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Replaces the cache-policy for the given key.

Returns false if the entry does not exist.

source

fn body<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 CacheKey, ) -> Pin<Box<dyn Future<Output = Option<Body>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Read/clone the cached body for the given key.

source

fn set<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 CacheKey, policy: CachePolicy, body: Body, ) -> Pin<Box<dyn Future<Output = Option<Body>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Caches the policy and body for the given key.

The body is fully downloaded and stored into the cache, this method can await for the full download before returning or return immediately with a body that updates as data is cached.

In case of error the cache entry is removed, the returned body may continue downloading data if possible. In case of a cache entry creation error the input body may be returned if it was not lost in the error.

source

fn remove<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 CacheKey, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Remove cached policy and body for the given key.

source

fn purge<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Remove all cached entries that are not locked in a set* operation.

source

fn prune<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Remove cache entries to reduce pressure.

What entries are removed depends on the cache DB implementer.

Implementors§